Added Copy-Method
This commit is contained in:
parent
7248becfcd
commit
58c579309a
26
PropertyCopy/Class.cs
Normal file
26
PropertyCopy/Class.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace PropertyCopy
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user