Skip to content

Commit f5dcef3

Browse files
committed
added support for .net core / net standard 1.3 (only safe variant)
1 parent 0e80222 commit f5dcef3

33 files changed

+11471
-61
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ obj
55
packages
66
.tools
77
.idea
8-
*.iml
8+
*.iml
9+
private.snk

DeepCloner.Core.sln

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.0.0
5+
MinimumVisualStudioVersion = 10.0.0.1
6+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "DeepCloner.Core", "DeepCloner\DeepCloner.xproj", "{CB0E426A-9468-48FA-9679-A782801F1D15}"
7+
EndProject
8+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "DeepCloner.Tests", "DeepCloner.Tests\DeepCloner.Tests.xproj", "{4939517A-4872-4CD3-9618-B3C69B68B688}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{61E9C5A9-C238-44DB-B8FC-C9440B1E6E16}"
11+
ProjectSection(SolutionItems) = preProject
12+
README.md = README.md
13+
EndProjectSection
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{CB0E426A-9468-48FA-9679-A782801F1D15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{CB0E426A-9468-48FA-9679-A782801F1D15}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{CB0E426A-9468-48FA-9679-A782801F1D15}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{CB0E426A-9468-48FA-9679-A782801F1D15}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{4939517A-4872-4CD3-9618-B3C69B68B688}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{4939517A-4872-4CD3-9618-B3C69B68B688}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{4939517A-4872-4CD3-9618-B3C69B68B688}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{4939517A-4872-4CD3-9618-B3C69B68B688}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(SolutionProperties) = preSolution
31+
HideSolutionNode = FALSE
32+
EndGlobalSection
33+
EndGlobal

DeepCloner.Tests/ArraysSpec.cs

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Force.DeepCloner.Tests
88
{
9+
#if !NETCORE
910
[TestFixture(false)]
11+
#endif
1012
[TestFixture(true)]
1113
public class ArraysSpec : BaseTest
1214
{

DeepCloner.Tests/CloneExtensionsSpec.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CloneExtensions;
1+
#if !NETCORE
2+
using CloneExtensions;
23

34
using NUnit.Framework;
45

@@ -141,3 +142,4 @@ public void AnonymousType_Should_be_Cloned()
141142
}
142143
}
143144
}
145+
#endif

DeepCloner.Tests/ConstructorsSpec.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Force.DeepCloner.Tests
66
{
7+
#if !NETCORE
78
[TestFixture(false)]
9+
#endif
810
[TestFixture(true)]
911
public class ConstructorsSpec : BaseTest
1012
{
@@ -64,6 +66,7 @@ public override string ToString()
6466
}
6567
}
6668

69+
#if !NETCORE
6770
public class ClonableClass : ICloneable
6871
{
6972
public object X { get; set; }
@@ -74,6 +77,15 @@ public object Clone()
7477
}
7578
}
7679

80+
[Test]
81+
public void Cloner_Should_Not_Call_Any_Method_Of_Clonable_Class()
82+
{
83+
// just for check, ensure no hidden behaviour in MemberwiseClone
84+
Assert.DoesNotThrow(() => new ClonableClass().DeepClone());
85+
Assert.DoesNotThrow(() => new { X = new ClonableClass() }.DeepClone());
86+
}
87+
#endif
88+
7789
[Test]
7890
public void Object_With_Private_Constructor_Should_Be_Cloned()
7991
{
@@ -103,6 +115,7 @@ public void Anonymous_Object_Should_Be_Cloned()
103115
Assert.That(cloned.B, Is.EqualTo("x"));
104116
}
105117

118+
#if !NETCORE
106119
private class C3 : ContextBoundObject
107120
{
108121
}
@@ -128,6 +141,7 @@ public void MarshalByRef_Object_Should_Be_Cloned()
128141
var cloned = c.DeepClone();
129142
Assert.That(cloned, Is.Not.Null);
130143
}
144+
#endif
131145

132146
[Test]
133147
public void Cloner_Should_Not_Call_Any_Method_Of_Class_Be_Cloned()
@@ -136,13 +150,5 @@ public void Cloner_Should_Not_Call_Any_Method_Of_Class_Be_Cloned()
136150
var exClass = new ExClass("x");
137151
Assert.DoesNotThrow(() => new[] { exClass, exClass }.DeepClone());
138152
}
139-
140-
[Test]
141-
public void Cloner_Should_Not_Call_Any_Method_Of_Clonable_Class()
142-
{
143-
// just for check, ensure no hidden behaviour in MemberwiseClone
144-
Assert.DoesNotThrow(() => new ClonableClass().DeepClone());
145-
Assert.DoesNotThrow(() => new { X = new ClonableClass() }.DeepClone());
146-
}
147153
}
148154
}
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
8+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
9+
<PropertyGroup Label="Globals">
10+
<ProjectGuid>{4939517A-4872-4CD3-9618-B3C69B68B688}</ProjectGuid>
11+
<ProjectTypeGuids>{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}</ProjectTypeGuids>
12+
<RootNamespace>DeepCloner.Tests1</RootNamespace>
13+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
14+
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
15+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
16+
</PropertyGroup>
17+
18+
<PropertyGroup>
19+
<SchemaVersion>2.0</SchemaVersion>
20+
</PropertyGroup>
21+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
22+
</Project>

DeepCloner.Tests/GenericsSpec.cs

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Force.DeepCloner.Tests
66
{
7+
#if !NETCORE
78
[TestFixture(false)]
9+
#endif
810
[TestFixture(true)]
911
public class GenericsSpec : BaseTest
1012
{

DeepCloner.Tests/Imported/FastDeepCloner.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// copied from https://raw.githubusercontent.com/Alenah091/FastDeepCloner/master/FastDeepCloner.cs because I need .NET 4.0 for tests
1+
#if !NETCORE
2+
// copied from https://raw.githubusercontent.com/Alenah091/FastDeepCloner/master/FastDeepCloner.cs because I need .NET 4.0 for tests
23
using System;
34
using System.Collections;
45
using System.Collections.Generic;
@@ -288,4 +289,5 @@ public enum FieldType
288289
FieldInfo,
289290
PropertyInfo
290291
}
291-
}
292+
}
293+
#endif

DeepCloner.Tests/InheritanceSpec.cs

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
namespace Force.DeepCloner.Tests
77
{
8+
#if !NETCORE
89
[TestFixture(false)]
10+
#endif
911
[TestFixture(true)]
1012
public class InheritanceSpec : BaseTest
1113
{

DeepCloner.Tests/PerformanceSpec.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if !NETCORE
2+
using System;
23
using System.Diagnostics;
34
using System.IO;
45
using System.Runtime.InteropServices;
@@ -250,3 +251,4 @@ public void Test_Shallow_Variants()
250251
}
251252
}
252253
}
254+
#endif

DeepCloner.Tests/PermissionSpec.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
#if !NETCORE
2+
using System;
23
using System.Security;
34
using System.Security.Permissions;
45

@@ -78,3 +79,4 @@ public void CloneExtensionsClone()
7879
}
7980
}
8081
}
82+
#endif

DeepCloner.Tests/ShallowClonerSpec.cs

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
namespace Force.DeepCloner.Tests
88
{
9+
#if !NETCORE
910
[TestFixture(false)]
11+
#endif
1012
[TestFixture(true)]
1113
public class ShallowClonerSpec : BaseTest
1214
{

DeepCloner.Tests/SimpleObjectSpec.cs

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace Force.DeepCloner.Tests
99
{
1010
[TestFixture(true)]
11+
#if !NETCORE
1112
[TestFixture(false)]
13+
#endif
1214
public class SimpleObjectSpec : BaseTest
1315
{
1416
public SimpleObjectSpec(bool isSafeInit)

DeepCloner.Tests/SystemTypesSpec.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
using System.Runtime.InteropServices;
66
using System.Security.Cryptography.X509Certificates;
77
using System.Text;
8-
98
using Microsoft.Win32.SafeHandles;
109

1110
using NUnit.Framework;
1211

1312
namespace Force.DeepCloner.Tests
1413
{
14+
#if !NETCORE
1515
[TestFixture(false)]
16+
#endif
1617
[TestFixture(true)]
1718
public class SystemTypesSpec : BaseTest
1819
{
@@ -48,16 +49,19 @@ public void Type_With_Native_Resource_Should_Be_Cloned()
4849
var cloned = writer.DeepClone();
4950
writer.Write("2");
5051
cloned.Write(3);
52+
#if !NETCORE
5153
var f = typeof(FileStream).GetField("_handle", BindingFlags.NonPublic | BindingFlags.Instance);
5254
var f2 = typeof(SafeHandle).GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance);
5355
Console.WriteLine(f2.GetValue(f.GetValue(writer.BaseStream)));
5456
Console.WriteLine(f2.GetValue(f.GetValue(cloned.BaseStream)));
55-
writer.Close();
57+
#endif
58+
59+
writer.Dispose();
5660
// cloned.Close();
5761
// not a bug anymore, this is feature: we don't duplicate handles, because it can cause unpredictable results
5862
// ~~this was a bug, we should not throw there~~
5963

60-
Assert.Throws<ObjectDisposedException>(cloned.Close);
64+
Assert.Throws<ObjectDisposedException>(cloned.Flush);
6165
var res = File.ReadAllText(fileName);
6266
Assert.That(res, Is.EqualTo("123"));
6367
}
@@ -130,9 +134,12 @@ public void Certificate_Should_Be_Cloned()
130134
cert.DeepClone();
131135
cert.DeepClone();
132136
GC.Collect();
137+
#if !NETCORE
133138
GC.WaitForFullGCComplete();
139+
#endif
134140
}
135141

142+
#if !NETCORE
136143
[Test(Description = "Without special handling it causes exception on destruction due native resources usage")]
137144
public void ObjectHandle_Should_Be_Cloned()
138145
{
@@ -144,6 +151,7 @@ public void ObjectHandle_Should_Be_Cloned()
144151
GC.Collect();
145152
GC.WaitForFullGCComplete();
146153
}
154+
#endif
147155

148156
[Test(Description = "Without special handling it causes exception on destruction due native resources usage")]
149157
public void Certificate_Should_Be_Shallow_Cloned()
@@ -152,7 +160,9 @@ public void Certificate_Should_Be_Shallow_Cloned()
152160
cert.ShallowClone();
153161
cert.ShallowClone();
154162
GC.Collect();
163+
#if !NETCORE
155164
GC.WaitForFullGCComplete();
165+
#endif
156166
}
157167
}
158168
}

DeepCloner.Tests/project.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"version": "1.0.0-*",
3+
"buildOptions": {
4+
"debugType": "portable",
5+
"allowUnsafe": true
6+
},
7+
"dependencies": {
8+
"DeepCloner": "*",
9+
"NUnit": "3.4.1"
10+
},
11+
12+
"testRunner": "nunit",
13+
14+
"frameworks": {
15+
"net40": {
16+
"dependencies": {
17+
"Clone.Behave": "1.0.1",
18+
"CloneExtensions": "1.2",
19+
"GeorgeCloney": "1.1.2.20",
20+
"NClone": "1.1.1",
21+
"Nuclex.Cloning": "1.0.0"
22+
}
23+
},
24+
"netcoreapp1.0": {
25+
"imports": "portable-net45+win8",
26+
"buildOptions": {
27+
"define": ["NETCORE"]
28+
},
29+
"dependencies": {
30+
"dotnet-test-nunit": "3.4.0-beta-3",
31+
"Microsoft.NETCore.App": {
32+
"version": "1.1.0-*",
33+
"type": "platform"
34+
}
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)