我正在尝试根据类中的String获取成员然后获取类型,但我没有运气。
Public Class Monster
Public Property Name As String
Public Property EatsPeople As Boolean
Public Property Description As String
End Class
要获取会员“EatsPeople”的详细信息,我会这样做:
Dim t = GetType(Monster) ' Get the type of the Product entity.
Dim fieldMemberInfo = t.GetMember("EatsPeople", BindingFlags.IgnoreCase Or BindingFlags.Public Or BindingFlags.Instance).Single()
无论我尝试什么组合,我要么得到Nothing,要么得到RuntimePropertyType
Dim x = fieldMemberInfo.GetType
答案 0 :(得分:2)
如果我正确理解你的问题,你只想获得" EatsPeople"属性。为此,使用PropertyInfo
更容易。
e.g。
Dim t = GetType(Monster) ' Get the type of the Product entity.
Dim propertyInfo = t.GetProperty("EatsPeople") 'Get the property info
Dim x = propertyInfo.PropertyType 'Get the type of the "Eats People" property.
答案 1 :(得分:0)
您可以像这样获取属性名称:
Dim t1 As PropertyInfo = fieldMemberInfo
Dim t2 = t1.PropertyType.FullName