Skip to content

Commit 6a466b5

Browse files
committed
Add CloneTest
1 parent c443a3f commit 6a466b5

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

src/Example.CSharp.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsolePollyTest", "plugins
277277
EndProject
278278
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePackTest", "plugins\MessagePackTest\MessagePackTest.csproj", "{16291F9D-48EC-496B-8610-E686CA57F747}"
279279
EndProject
280+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CloneTest", "plugins\CloneTest\CloneTest.csproj", "{E8A64A5D-8052-499B-9CC6-09C2768EDDAA}"
281+
EndProject
280282
Global
281283
GlobalSection(SolutionConfigurationPlatforms) = preSolution
282284
Debug|Any CPU = Debug|Any CPU
@@ -675,6 +677,10 @@ Global
675677
{16291F9D-48EC-496B-8610-E686CA57F747}.Debug|Any CPU.Build.0 = Debug|Any CPU
676678
{16291F9D-48EC-496B-8610-E686CA57F747}.Release|Any CPU.ActiveCfg = Release|Any CPU
677679
{16291F9D-48EC-496B-8610-E686CA57F747}.Release|Any CPU.Build.0 = Release|Any CPU
680+
{E8A64A5D-8052-499B-9CC6-09C2768EDDAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
681+
{E8A64A5D-8052-499B-9CC6-09C2768EDDAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
682+
{E8A64A5D-8052-499B-9CC6-09C2768EDDAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
683+
{E8A64A5D-8052-499B-9CC6-09C2768EDDAA}.Release|Any CPU.Build.0 = Release|Any CPU
678684
EndGlobalSection
679685
GlobalSection(SolutionProperties) = preSolution
680686
HideSolutionNode = FALSE
@@ -791,6 +797,7 @@ Global
791797
{F4FAEA96-D8F1-4C3D-83EF-A121BAFD2EA1} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
792798
{7F0AA476-83A6-49C7-9064-6D13EF4811B9} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
793799
{16291F9D-48EC-496B-8610-E686CA57F747} = {630114C3-1AE7-468E-8ADD-1CDE3E9EEF26}
800+
{E8A64A5D-8052-499B-9CC6-09C2768EDDAA} = {630114C3-1AE7-468E-8ADD-1CDE3E9EEF26}
794801
EndGlobalSection
795802
GlobalSection(ExtensibilityGlobals) = postSolution
796803
SolutionGuid = {CBE0CD6C-2E47-4D9F-B072-C138AA4A6D5A}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Dolly" Version="0.0.9">
12+
<PrivateAssets>all</PrivateAssets>
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
</PackageReference>
15+
</ItemGroup>
16+
17+
</Project>

src/plugins/CloneTest/DollyTest.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
namespace CloneTest;
2+
3+
public static class DollyTest
4+
{
5+
6+
#region Constants & Statics
7+
8+
public static void ComplexClassTest()
9+
{
10+
var a = new ComplexClass(
11+
new SimpleRecord("Test", 42) { DontClone = 3.14f },
12+
new SimpleClass { First = "Test", Second = 42, DontClone = 3.14f })
13+
{
14+
Third = 7
15+
};
16+
17+
var b = a.DeepClone();
18+
19+
Console.WriteLine($"{b.SimpleRecord.First} {b.SimpleClass.DontClone} {b.Third}");
20+
}
21+
22+
public static void SimpleClassTest()
23+
{
24+
var a = new SimpleClass { First = "Test", Second = 42, DontClone = 3.14f };
25+
26+
var b = a.DeepClone();
27+
28+
Console.WriteLine($"{b.First} {b.DontClone}");
29+
}
30+
31+
public static void SimpleRecordTest()
32+
{
33+
var a = new SimpleRecord("Test", 42) { DontClone = 3.14f };
34+
35+
var b = a.DeepClone();
36+
37+
Console.WriteLine($"{b.First} {b.DontClone}");
38+
}
39+
40+
#endregion
41+
42+
}

src/plugins/CloneTest/Program.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace CloneTest;
2+
3+
public static class Program
4+
{
5+
6+
#region Constants & Statics
7+
8+
public static void Main(string[] args)
9+
{
10+
DollyTest.SimpleClassTest();
11+
DollyTest.SimpleRecordTest();
12+
DollyTest.ComplexClassTest();
13+
}
14+
15+
#endregion
16+
17+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Dolly;
2+
3+
namespace CloneTest;
4+
5+
[Clonable]
6+
public partial class SimpleClass
7+
{
8+
9+
#region Properties
10+
11+
[CloneIgnore]
12+
public float DontClone { get; set; }
13+
14+
public required string First { get; set; }
15+
16+
public int Second { get; set; }
17+
18+
#endregion
19+
20+
}
21+
22+
[Clonable]
23+
public partial record SimpleRecord(string First, int Second)
24+
{
25+
26+
#region Properties
27+
28+
[CloneIgnore]
29+
public float DontClone { get; init; }
30+
31+
#endregion
32+
33+
}
34+
35+
[Clonable]
36+
public partial class ComplexClass
37+
{
38+
public ComplexClass(SimpleRecord simpleRecord, SimpleClass simpleClass)
39+
{
40+
SimpleRecord = simpleRecord;
41+
SimpleClass = simpleClass;
42+
}
43+
44+
#region Properties
45+
46+
public SimpleClass SimpleClass { get; private set; }
47+
48+
public SimpleRecord SimpleRecord { get; private set; }
49+
50+
public int Third { get; set; }
51+
52+
#endregion
53+
54+
}

0 commit comments

Comments
 (0)