Reflection/Linq:在 vb.net 中的另一个中查找 class
Reflection/Linq: Find class inside another in vb.net
我的代码中有下一个 class:
Public Class MyClass
Public Class MyDictionary
Public Shared Property something As String = "xxxxx"
...
End Class
Public Property dbId As Integer
Public Property dbDescription As String
Public Property Activate As Boolean
...
End Class
我想做的是使用 Linq 查找 MyDictionary class 的 propertyInfo。
我尝试使用
Dim propertyInfo = typeDest.GetProperty("MyDictionary", BindingFlags.IgnoreCase Or BindingFlags.Public Or BindingFlags.Instance)
但是什么都没给我。
可以吗?
MyDictionary
不是 属性。这是一个class。您无法通过 GetProperty
.
找到它
你必须这样做:
Dim myDictionaryType As Type = _
GetType([MyClass]) _
.Assembly _
.GetTypes() _
.Where(Function(x) x.FullName.StartsWith(GetType([MyClass]).FullName)) _
.Where(Function(x) x.Name = "MyDictionary")
.FirstOrDefault()
我的代码中有下一个 class:
Public Class MyClass
Public Class MyDictionary
Public Shared Property something As String = "xxxxx"
...
End Class
Public Property dbId As Integer
Public Property dbDescription As String
Public Property Activate As Boolean
...
End Class
我想做的是使用 Linq 查找 MyDictionary class 的 propertyInfo。
我尝试使用
Dim propertyInfo = typeDest.GetProperty("MyDictionary", BindingFlags.IgnoreCase Or BindingFlags.Public Or BindingFlags.Instance)
但是什么都没给我。
可以吗?
MyDictionary
不是 属性。这是一个class。您无法通过 GetProperty
.
你必须这样做:
Dim myDictionaryType As Type = _
GetType([MyClass]) _
.Assembly _
.GetTypes() _
.Where(Function(x) x.FullName.StartsWith(GetType([MyClass]).FullName)) _
.Where(Function(x) x.Name = "MyDictionary")
.FirstOrDefault()