开发者

Class Property in for each

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() a开发者_Python百科s 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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜