vb.net通过Type类型实现自动拷贝各属性的值
Public Sub copyTo(ByVal pObject As CopyBase, ByVal pType As Type)
If (pType Is Nothing) Then
Return
End If
Dim pPropertyInfos As PropertyInfo() = pType.GetProperties()
For Each p As PropertyInfo In pPropertyInfos
If (p.CanRead AndAlso p.CanWrite) Then
If (p.GetIndexParameters() IsNot Nothing AndAlso p.GetIndexParameters().Length > 0) Then '排除带属性索引的字段,带索引的字段必须手工复制
Continue For
End If
p.SetValue(pObject, p.GetValue(Me, Nothing), Nothing)
End If
Next
End Sub