在.NET中使用反射匹配类型
我试图使用反射从返回特定类型的类中收集属性。但是,我返回的一些属性是强类型列表,其中包含我想要的类型。 基本上,我正在尝试做以下工作:在.NET中使用反射匹配类型,.net,reflection,system.type,.net,Reflection,System.type,我试图使用反射从返回特定类型的类中收集属性。但是,我返回的一些属性是强类型列表,其中包含我想要的类型。 基本上,我正在尝试做以下工作: Public Function GetPropertyInfo(ByVal t as System.Type) for each pi as System.Reflection.PropertyInfo in ob.GetType.GetProperties() if pi.PropertyType.equals(GetType(List(Of
Public Function GetPropertyInfo(ByVal t as System.Type)
for each pi as System.Reflection.PropertyInfo in ob.GetType.GetProperties()
if pi.PropertyType.equals(GetType(List(Of t)))
return pi
end if
next
Return Nothing
End Function
显然,这不起作用,因为它会抛出一个错误,说明t不是声明的类型。有没有办法做到这一点
谢谢。在C#中,您正在查找以下语法:
Type desiredPropertyType = typeof(List<>).MakeGenericType(new Type[] { t });
Dim desiredPropertyType As Type = GetType(List(Of )).MakeGenericType(New Type() { t })