每个类的属性
我在迭代类属性时遇到问题。
我有我的第一个类:
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
现在,当我从以下代码迭代类属性时,
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
我得到 UIN、Name、ItemCategory,但我期望 UIN、Name 和 Category。
我对此有点不清楚,不知道为什么会发生这种情况?我应该做什么来纠正它?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这没有意义。您正在检索属性的基础类型的名称,您应该获得类似 System.String、System.Int32 和 ItemCategory 之类的名称。
如果您要的是属性名称,则可以仅使用
PropertyInfo.Name
,在您的情况下: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: