-
Notifications
You must be signed in to change notification settings - Fork 3
Custom properties
Oliver Ehrenmüller edited this page Aug 31, 2019
·
2 revisions
If you have a property that requires extra logic, you can inject copy instruction of remaining properties
- Mark copy constructor with
InjectDeepCopy
- Mark special property with
IgnoreDuringDeepCopy
- Copy-Instructions are added before your code.
public class ClassWithCopyConstructor
{
public int Integer { get; set; }
public IList<int> Integers { get; set; }
[IgnoreDuringDeepCopy]
public SpecialClass SpecialObject { get; set; }
public ClassWithCopyConstructor() { }
[InjectDeepCopy]
public ClassWithCopyConstructor(ClassWithCopyConstructor source)
{
SpecialObject = SpecialLogic.SpecialCopy(source.SpecialObject);
}
}
public class ClassWithCopyConstructor
{
public int Integer { get; set; }
public IList<int> Integers { get; set; }
public SpecialClass SpecialObject { get; set; }
public ClassWithCopyConstructor() { }
public ClassWithCopyConstructor(ClassWithCopyConstructor source)
{
this.Integer = source.Integer;
if (source.Integers != null)
{
this.Integers = (IList<int>) new List<int>();
for (int index = 0; index < source.Integers.Count; ++index)
this.Integers.Add(source.Integers[index]);
}
SpecialObject = SpecialLogic.SpecialCopy(source.SpecialObject);
}
}