兩個同型物件取代其屬性內容
以下提供快簡短的方式來作屬性內容的取代,也就是 Source物件屬性內容,取代Target物件屬性內容
Public Sub ReplaceObject(ByVal source As Object, ByVal target As Object)
For Each tp In source.GetType().GetProperties()
tp.SetValue(target, tp.GetValue(source, Nothing), Nothing)
Next
End Sub
public void ReplaceObject(Object source, Object target)
{
foreach (var tp in source.GetType().GetProperties())
{
tp.SetValue(target, tp.GetValue(source, null), null);
}
}