Static Copy Method
I keep this in a static class called ManipulateModels
public static void CopyTo(this object S, object T)
{
//Works fine however if a default value is set then it will need to be handled or it will be reset
var notNullProps = S.GetType().GetProperties()
.Where(x => x.GetValue(S, null) != null);
foreach (var pS in S.GetType().GetProperties())
{
foreach (var pT in T.GetType().GetProperties())
{
//example for Default Value
//had to do this due to setting a default value of 0
//if (pT.Name == "BuildingID") continue;
if (pT.Name != pS.Name) continue;
object x = pS.GetValue(S, null);
if (x != null)
{
(pT.GetSetMethod()).Invoke(T, new object[] { pS.GetGetMethod().Invoke(S, null) });
}
}
};
//foreach (var pS in notNullProps.GetType().GetProperties())
}
public static void CopyTo(this object S, object T)
{
//Works fine however if a default value is set then it will need to be handled or it will be reset
var notNullProps = S.GetType().GetProperties()
.Where(x => x.GetValue(S, null) != null);
foreach (var pS in S.GetType().GetProperties())
{
foreach (var pT in T.GetType().GetProperties())
{
//example for Default Value
//had to do this due to setting a default value of 0
//if (pT.Name == "BuildingID") continue;
if (pT.Name != pS.Name) continue;
object x = pS.GetValue(S, null);
if (x != null)
{
(pT.GetSetMethod()).Invoke(T, new object[] { pS.GetGetMethod().Invoke(S, null) });
}
}
};
//foreach (var pS in notNullProps.GetType().GetProperties())
}
Comments