PASTE-IT!

Holding 522M in 34869 pastes. Meet us at #paste-it.net, OFTC!
Try our Mozilla Jetpack clipboard paster and our Chrome extension!
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Option Strict On

Imports System.Reflection

Public Class PropertyMover

    Public Shared Sub MoveProperties(ByVal source As Object, ByVal destination As Object)
        Dim sourceProperties = source.GetType().GetProperties(BindingFlags.Public Or BindingFlags.Instance)
        Dim destinationProperties = destination.GetType().GetProperties(BindingFlags.Public Or BindingFlags.Instance)

        For Each propertyInfo As PropertyInfo In sourceProperties
            Dim propertyName As String = propertyInfo.Name
            Dim sourceValue As Object = propertyInfo.GetValue(source, Nothing)

            Dim matchedProperties = From propInfo In destinationProperties _
                                    Where propInfo.Name = propertyName

            If matchedProperties.Count > 0 Then
                matchedProperties(0).SetValue(destination, sourceValue, Nothing)
            End If
        Next
    End Sub

End Class
Property Mover
by
Seth Rowe
pasted
524 day(s) ago
13:21 03-09-2008
in syntax