views:

31

answers:

1

Hi guys,

I am running from a problem while iterating over class properties.

I have my first class:

class Item
  private _UIN as integer = 0
  private _Name as string = ""
  private _Category as ItemCategory = new ItemCategory()

  public Property UIN() as integer
  public property Name() as string
  public property Category() as ItemCategory 

end class

Now when i iterate over the class properties from following code

Dim AllProps As System.Reflection.PropertyInfo()
Dim PropA As System.Reflection.PropertyInfo
dim ObjA as object

AllProps = new Item().getType().getProperties()
for each propA in AllProps
   ObjA = PropA.GetValue(myObj, New Object() {})
   debug.write ObjA.GetType().Name
next

I get UIN, Name, ItemCategory but i expected UIN, Name and Category.

I am a bit unclear about this and dun know why this is happening? What should i do to correct it?

+1  A: 

I get UIN, Name, ItemCategory

That doesn't make sense. You're retrieving the names of the underlying type of the property, you should've gotten something like System.String, System.Int32 and ItemCategory.

If it's the property names you're after, you can just use PropertyInfo.Name, in your case:

AllProps = new Item().getType().getProperties()
for each propA in AllProps
   debug.write propA.Name
next
Willem van Rumpt
Yeah propA.Name gave me the result i wanted but it didn't lead to my solution i was expecting. Actually I was trying to solve my next proplem and thought it was giving problem. My Actual Problem is:http://stackoverflow.com/questions/3042804/how-to-assign-class-property-as-display-data-member-in-datagridview
KoolKabin