reflection on interfaces

  • Thread starter Thread starter Trapulo
  • Start date Start date
T

Trapulo

I have a reference to an object via a specific interface.
I need to read a propery of this object via reflection, and I have only the
property name. My problem is that I cannot retrieve a type reference to the
type of the object I have, because my reference is on an interface. Is there
aby way to solve this problem? Can I access a property of the object via
reflection, having a reference to the object via interface and the name of
the property?

thanks
 
Use the TypeDescriptor to get a PropertyDescriptorCollection for the object
like this...

Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(<the
object>)

Dim sb As New StringBuilder

Dim pd As PropertyDescriptor



For Each pd In pdc

sb.Append(pd.Name & vbCrLf)

Next

MessageBox.Show(sb.ToString())


--
Bob Powell

Get a free issue of Well Formed VB edition.
http://www.bobpowell.net/vb_offer.htm

What's Well Formed?
http://www.bobpowell.net/currentissue.htm

Visit the GDI+ FAQ for articles, tips, tricks and code.
http://www.bobpowell.net/gdiplus_faq.htm

Read my blog
http://bobpowelldotnet.blogspot.com
 
It works!

thanks


Bob Powell said:
Use the TypeDescriptor to get a PropertyDescriptorCollection for the object
like this...

Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(<the
object>)

Dim sb As New StringBuilder

Dim pd As PropertyDescriptor



For Each pd In pdc

sb.Append(pd.Name & vbCrLf)

Next

MessageBox.Show(sb.ToString())


--
Bob Powell

Get a free issue of Well Formed VB edition.
http://www.bobpowell.net/vb_offer.htm

What's Well Formed?
http://www.bobpowell.net/currentissue.htm

Visit the GDI+ FAQ for articles, tips, tricks and code.
http://www.bobpowell.net/gdiplus_faq.htm

Read my blog
http://bobpowelldotnet.blogspot.com
 
Back
Top