Added Copy-Method

This commit is contained in:
Railz 2020-03-02 15:14:00 +01:00
parent 7248becfcd
commit 58c579309a
2 changed files with 26 additions and 8 deletions

26
PropertyCopy/Class.cs Normal file
View File

@ -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;
}
}
}
}
}
}

View File

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