0

我正在尝试根据类中的字符串获取成员,然后获取类型,但我没有任何运气。

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
4

2 回答 2

3

如果我正确理解您的问题,您只想获取“EatsPeople”属性的类型。为此,它更易于使用PropertyInfo

例如

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.
于 2013-02-03T05:32:59.197 回答
0

您可以像这样获取属性名称:

Dim t1 As PropertyInfo = fieldMemberInfo
Dim t2 = t1.PropertyType.FullName
于 2013-02-03T11:05:48.013 回答