2010-06-15 7 views
1

클래스 속성을 반복하는 동안 문제가 발생합니다. 클래스 각각의 속성

나는 나의 첫 수업이 : 내가 코드를 다음에서 클래스의 속성을 반복 할 때 이제

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는, 이름, ItemCategory하지만 난 UIN, 이름과 카테고리를 예상 얻을 .

나는 이것에 대해 약간 불분명하며 왜 이런 일이 일어나고 있는지 알고있다. 문제를 해결하려면 어떻게해야합니까?

답변

1

나는 이해가되지 않습니다 UIN, 이름, ItemCategory

를 얻을. 기본 유형의 속성 이름을 검색하면 System.String, System.Int32 및 ItemCategory와 같은 것을 얻었어야합니다.

그 후 당신 재산 이름이 있다면, 당신은 당신의 경우, PropertyInfo.Name를 사용할 수 있습니다

AllProps = new Item().getType().getProperties() 
for each propA in AllProps 
    debug.write propA.Name 
next 
+0

그래 propA.Name 나에게 내가 원하는 결과를 준하지만이 이어질하지 않았다 내 해결책은 내가 기대하고 있었다. 사실 저는 다음 proplem을 해결하려고 노력하고 있었고 그것이 문제를주고 있다고 생각했습니다. 내 실제 문제 : http://stackoverflow.com/questions/3042804/how-to-assign-class-property-as-display-data-member-in-datagridview – KoolKabin