Sub Class Reflection 
Author Message
 Sub Class Reflection

I have a class that contains methods, properties, and fields.

I can us reflection and acquire the propertie names and values with no
problem.
    In this example i can get the properties in the Master class and methods

I want to be able to do the same thing with a field. I can get the field
names. But I want the field's property names and their values.
eg..

Class Master
    Private m_stuff as string
    .....
    Public Property GoodStuff() As string
    .....
    .....
End Class

Class A
    Inherits Master

    Public stuff as new B

End Class

Class B
    Private Val as string

    Public Property GetVal() As string
        Get
            Return val
        End Get
        Set(ByVal Value as string)
            val = value
        End Set
    End Property
End Class

typically you can say
    Dim classA as new a
    classA.stuff.getval = "01"

however i want my wrking class to be smart and discover the structure of a
class.

acquire the propertie names and values of properties with no problem.
eg ...

Dim wrk_class as Type = GetType(A)
Dim wrk_class_Properties As PropertyInfo() =
wrk_class.GetProperties((System.Reflection.BindingFlags.Public Or
System.Reflection.BindingFlags.Instance))
For q = 0 To wrk_class_Properties.Length - 1
    Dim wrk_class_PropInfo As System.Reflection.PropertyInfo =
CType(wrk_class_Properties(q), System.Reflection.PropertyInfo)
    Debug.Write("Property: " + wrk_class_PropInfo.Name() + " = " +
wrk_class_PropInfo.GetValue(item, Nothing) + ControlChars.CrLf)
Next q

Thanks
Tim Fortney



Wed, 16 Feb 2005 00:36:59 GMT  
 Sub Class Reflection
Tim,

There's a property on PropertyInfo called PropertyType which returns a
System.Type object.  You can then use this Type object just as you did for
Class A.

hope this helps,
Cameron

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I have a class that contains methods, properties, and fields.

> I can us reflection and acquire the propertie names and values with no
> problem.
>     In this example i can get the properties in the Master class and
methods

> I want to be able to do the same thing with a field. I can get the field
> names. But I want the field's property names and their values.
> eg..

> Class Master
>     Private m_stuff as string
>     .....
>     Public Property GoodStuff() As string
>     .....
>     .....
> End Class

> Class A
>     Inherits Master

>     Public stuff as new B

> End Class

> Class B
>     Private Val as string

>     Public Property GetVal() As string
>         Get
>             Return val
>         End Get
>         Set(ByVal Value as string)
>             val = value
>         End Set
>     End Property
> End Class

> typically you can say
>     Dim classA as new a
>     classA.stuff.getval = "01"

> however i want my wrking class to be smart and discover the structure of a
> class.

> acquire the propertie names and values of properties with no problem.
> eg ...

> Dim wrk_class as Type = GetType(A)
> Dim wrk_class_Properties As PropertyInfo() =
> wrk_class.GetProperties((System.Reflection.BindingFlags.Public Or
> System.Reflection.BindingFlags.Instance))
> For q = 0 To wrk_class_Properties.Length - 1
>     Dim wrk_class_PropInfo As System.Reflection.PropertyInfo =
> CType(wrk_class_Properties(q), System.Reflection.PropertyInfo)
>     Debug.Write("Property: " + wrk_class_PropInfo.Name() + " = " +
> wrk_class_PropInfo.GetValue(item, Nothing) + ControlChars.CrLf)
> Next q

> Thanks
> Tim Fortney



Wed, 16 Feb 2005 04:44:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Possible to use Reflection on Registry Class?

2. Using reflection to create class instance

3. VB2008: Getting the System.Reflection.PropertyInfo from within a class property

4. Class and Sub Class ?

5. Class and Sub Class ?

6. Class and Sub Class ?

7. menus and sub-menus and sub-sub-menus

8. count elements in root, sub root sub-sub root treeview

9. Start sub in Class

10. Form drops into design mode and disables class subs

11. Retrieve name of Function, Sub, Class, Property etc from within that item during runtime

12. Calling a sub from another class

 

 
Powered by phpBB® Forum Software