Added Copy-Method

master
Railz 5 years ago
parent 7248becfcd
commit 58c579309a

@ -0,0 +1,26 @@
using System;
namespace PropertyCopy
{
public static class Class
{
public static void CopyPropertiesFrom(this object self, object parent)
{
var fromProperties = parent.GetType().GetProperties();
var toProperties = self.GetType().GetProperties();
foreach (var fromProperty in fromProperties)
{
foreach (var toProperty in toProperties)
{
if (fromProperty.Name == toProperty.Name && fromProperty.PropertyType == toProperty.PropertyType)
{
toProperty.SetValue(self, fromProperty.GetValue(parent));
break;
}
}
}
}
}
}

@ -1,8 +0,0 @@
using System;
namespace PropertyCopy
{
public class Class1
{
}
}
Loading…
Cancel
Save