我需要加载大约10个类的所有属性,我正在使用接口将类加载到列表中。
尝试加载为单独的类,它可以正常工作,如下所示,
Dim t As Type
t = GetType(ClassA)
For Each prop As PropertyInfo In t.GetProperties()
FieldnameObjects = New FieldnameObjects
FieldnameObjects.ClassName = prop.DeclaringType.Name.ToString()
FieldnameObjects.FieldName = prop.DeclaringType.Name.ToString() + "." + prop.Name.ToString()
FieldnameObjects.FieldNameObj = prop.Name.ToString()
FieldnameObjects.FieldType = prop.PropertyType.Name.ToString()
newList.Add(FieldnameObjects)
Next
其中FieldnameObjects
是包含这4个字段的自定义类。但我需要加载多个类字段,所以我尝试了下面的代码,
Public Interface IClassTypes
Property Class1() As ClassA
Property Class2() As ClassB
Property Class3() As ClassC
Property Class4() As ClassD
End Interface
当我尝试从上面的列表中加载属性时,它无法正常工作。
尝试了类似的事情,
Dim t As Type
t = GetType(IClassTypes.Class1)
有没有办法可以在列表中加载一些类并循环来一次获取所有字段而不是单独加载它?
像这样,
For Each prop As object In LisfOfClasses()
Dim t As Type
t = GetType(prop.Class1)
For Each prop As PropertyInfo In t.GetProperties()
//Code here
Next
Next