我正在尝试使用反射来遍历我的类属性,在这里尝试使用一些线程作为指导,但是propertyInfo数组始终不返回任何内容。
Public Sub GetProperties(ByRef objType As Type)
Dim propertyInfo() As PropertyInfo = objType.GetProperties((BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.DeclaredOnly))
For Each propertyItem As System.Reflection.PropertyInfo In propertyInfo
Console.WriteLine(propertyItem.Name & " is of type " & propertyItem.PropertyType.ToString)
Console.WriteLine(vbCrLf & vbCrLf)
Next
End Sub
Imports System.Data.SqlClient
Imports System.Web
Imports System.IO
Public Class Collection
Inherits AppBase
Public Sub New(ByVal newConnectionString As String, ByVal newAppBrand As String, ByVal newRepID As Integer)
MyBase.New(newConnectionString, newAppBrand, newRepID)
End Sub
Public Class CollectionRecord
Inherits AppRecord
Public collectionID As Integer
Public name As String
Public sqmBasePrice As Long
Public summary As String
Public imageName As String
End Class
Module DownloadData
Public Function CheckData
Dim collectionRecord as new CollectionRecord
GetProperties(collectionRecord)
End Function
End Module
如果我在GetProperties参数中用字符串类型替换自定义类,则会得到两个返回的属性。有任何想法吗?
谢谢保罗
您定义的类型CollectionRecord
具有五个字段,但没有属性。
Public Class CollectionRecord
Inherits AppRecord
Public collectionID As Integer
Public name As String
Public sqmBasePrice As Long
Public summary As String
Public imageName As String
End Class
然后,您可以使用反射API遍历该类型的属性。
这里的解决方案是:
1和2都可以使用,仅取决于您的需求。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句