Skip to content

Commit 1927c08

Browse files
committed
v0.10.0 updated documentation
1 parent 34cd426 commit 1927c08

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

DeepCloner.Tests/CopyToObjectSpec.cs

+25
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,30 @@ public void Dictionary_Should_Be_Deeply_Cloned()
381381
Assert.That(d2.Count, Is.EqualTo(1000));
382382
Assert.That(d2["557"], Is.EqualTo("557"));
383383
}
384+
385+
public class D1
386+
{
387+
public int A { get; set; }
388+
}
389+
390+
public class D2 : D1
391+
{
392+
public int B { get; set; }
393+
394+
public D2(D1 d1)
395+
{
396+
B = 14;
397+
d1.DeepCloneTo(this);
398+
}
399+
}
400+
401+
[Test]
402+
public void Inner_Implementation_In_Class_Should_Work()
403+
{
404+
var baseObject = new D1 { A = 12 };
405+
var wrapper = new D2(baseObject);
406+
Assert.That(wrapper.A, Is.EqualTo(12));
407+
Assert.That(wrapper.B, Is.EqualTo(14));
408+
}
384409
}
385410
}

DeepCloner.nuspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>DeepCloner</id>
55
<title>DeepCloner</title>
6-
<version>0.9.4</version>
6+
<version>0.10.0</version>
77
<authors>force</authors>
88
<owners>force</owners>
99
<licenseUrl>https://github.com/force-net/DeepCloner/blob/develop/LICENSE</licenseUrl>
@@ -12,7 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>Small Library for fast deep or shallow cloning .NET objects. It allows to copy everything and has a lot of performance tricks for fast copying.</description>
1414
<releaseNotes>
15-
Added support for .NET Standard (.NET Core)
15+
Added additional methods for cloning DeepCloneTo/ShallowCloneTo
1616
</releaseNotes>
1717
<copyright>Copyright by Force 2016-2017</copyright>
1818
<tags>.NET shallow deep clone DeepClone fast</tags>

README.md

+23
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,29 @@ Shallow cloning (clone only same object, not objects that object relate to)
4747
var clone = new { Id = 1, Name = "222" }.ShallowClone();
4848
```
4949

50+
Cloning to existing object (can be useful for _copying_ constructors, creating wrappers or for keeping references to same object)
51+
```
52+
public class Derived : BaseClass
53+
{
54+
public Derived(BaseClass parent)
55+
{
56+
parent.DeepCloneTo(this); // now this has every field from parent
57+
}
58+
}
59+
```
60+
Please, note, that _DeepCloneTo_ and _ShallowCloneTo_ requre that object should be class (it is useless for structures) and derived class must be real descendant of parent class (or same type). In another words, this code will not work:
61+
```
62+
public class Base {}
63+
public class Derived1 : Base {}
64+
public class Derived2 : Base {}
65+
66+
var b = (Base)new Derived1(); // casting derived to parent
67+
var derived2 = new Derived2();
68+
// will compile, but will throw an exception in runtime, Derived1 is not parent for Derived2
69+
b.DeepCloneTo(derived2);
70+
71+
```
72+
5073
## Installation
5174

5275
Through nuget:

0 commit comments

Comments
 (0)