G
Guest
Hi all
I am using reflection to read the values of properties from a class. The
class is returned from a Web Service so I have to access the class using
FieldInfo (Using VS 2003 which converts the Properties into Fields when it
comes out of the Web Service).
I have this at the moment:
Private _aDataSource As Object 'Person class
Dim aFieldInfo as FieldInfo = _aDataSource.GetType.GetField("FirstName")
Dim aValue As Object = _aFieldInfo.GetValue(_aDataSource)
aValue ="Steve"
Using this, I can get the FirstName field value from the class, but I want
to read the values from a nested Class as well. For example, I have a class
called Person, and in that class is another class called Address. I want to
be able to read the value of AddressLine1 from the Address class within the
Person class using reflection.
I can do the following to get the Address class:
Dim aFieldInfo as FieldInfo = _aDataSource.GetType.GetField("Address")
but if I try to access the fields on that class then I get an exception
about Object types not being able to be converted to target types (or
something like that!).
So, using reflection, how can I access the value of the field AddressLine1
from the Address class that is in the Person class?
Thank you for any help.
Kind Regards,
Steve
I am using reflection to read the values of properties from a class. The
class is returned from a Web Service so I have to access the class using
FieldInfo (Using VS 2003 which converts the Properties into Fields when it
comes out of the Web Service).
I have this at the moment:
Private _aDataSource As Object 'Person class
Dim aFieldInfo as FieldInfo = _aDataSource.GetType.GetField("FirstName")
Dim aValue As Object = _aFieldInfo.GetValue(_aDataSource)
aValue ="Steve"
Using this, I can get the FirstName field value from the class, but I want
to read the values from a nested Class as well. For example, I have a class
called Person, and in that class is another class called Address. I want to
be able to read the value of AddressLine1 from the Address class within the
Person class using reflection.
I can do the following to get the Address class:
Dim aFieldInfo as FieldInfo = _aDataSource.GetType.GetField("Address")
but if I try to access the fields on that class then I get an exception
about Object types not being able to be converted to target types (or
something like that!).
So, using reflection, how can I access the value of the field AddressLine1
from the Address class that is in the Person class?
Thank you for any help.
Kind Regards,
Steve