diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..940865e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*.pdb +*.exe +**/obj/** +*.dll +*.class +**/bin/** diff --git a/ObjectExtensions.cs b/ObjectExtensions.cs index 02ea1cc..0c58025 100644 --- a/ObjectExtensions.cs +++ b/ObjectExtensions.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Reflection; using System.ArrayExtensions; +using System.Xml.Linq; namespace System { @@ -23,6 +24,7 @@ private static Object InternalCopy(Object originalObject, IDictionary + + + + Debug + AnyCPU + {7900459D-F2F7-461F-948A-FFE4EEFF6148} + Library + Properties + netobjdeepcopy + netobjdeepcopy + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/netobjdeepcopy.sln b/netobjdeepcopy.sln new file mode 100644 index 0000000..ba83e3f --- /dev/null +++ b/netobjdeepcopy.sln @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "netobjdeepcopy", "netobjdeepcopy.csproj", "{7900459D-F2F7-461F-948A-FFE4EEFF6148}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "unittests", "unittests\unittests.csproj", "{F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7900459D-F2F7-461F-948A-FFE4EEFF6148}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7900459D-F2F7-461F-948A-FFE4EEFF6148}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7900459D-F2F7-461F-948A-FFE4EEFF6148}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7900459D-F2F7-461F-948A-FFE4EEFF6148}.Release|Any CPU.Build.0 = Release|Any CPU + {F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/netobjdeepcopy.sln.DotSettings.user b/netobjdeepcopy.sln.DotSettings.user new file mode 100644 index 0000000..0d70c86 --- /dev/null +++ b/netobjdeepcopy.sln.DotSettings.user @@ -0,0 +1,4 @@ + + True + ObjectExtensionsTests + <Session><Elements><UnitTestElement Provider="MSTest" Id="MsTest:unittests.ObjectExtensionsTests" type="MsTestTestClassElement" TypeName="unittests.ObjectExtensionsTests" Project="F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B" /><UnitTestElement Provider="MSTest" Id="MsTest:unittests.ObjectExtensionsTests.Copy_CopiesEnumerables" ParentId="MsTest:unittests.ObjectExtensionsTests" type="MsTestTestMethodElement" MethodName="Copy_CopiesEnumerables" TypeName="unittests.ObjectExtensionsTests" Project="F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B" /><UnitTestElement Provider="MSTest" Id="MsTest:unittests.ObjectExtensionsTests.Copy_CopiesNestedObject" ParentId="MsTest:unittests.ObjectExtensionsTests" type="MsTestTestMethodElement" MethodName="Copy_CopiesNestedObject" TypeName="unittests.ObjectExtensionsTests" Project="F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B" /><UnitTestElement Provider="MSTest" Id="MsTest:unittests.ObjectExtensionsTests.Copy_CopiesSingleBuiltInObjects" ParentId="MsTest:unittests.ObjectExtensionsTests" type="MsTestTestMethodElement" MethodName="Copy_CopiesSingleBuiltInObjects" TypeName="unittests.ObjectExtensionsTests" Project="F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B" /><UnitTestElement Provider="MSTest" Id="MsTest:unittests.ObjectExtensionsTests.Copy_CopiesSingleObject" ParentId="MsTest:unittests.ObjectExtensionsTests" type="MsTestTestMethodElement" MethodName="Copy_CopiesSingleObject" TypeName="unittests.ObjectExtensionsTests" Project="F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B" /><UnitTestElement Provider="MSTest" Id="MsTest:unittests.ObjectExtensionsTests.Copy_XElementWithChildren" ParentId="MsTest:unittests.ObjectExtensionsTests" type="MsTestTestMethodElement" MethodName="Copy_XElementWithChildren" TypeName="unittests.ObjectExtensionsTests" Project="F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B" /></Elements></Session> \ No newline at end of file diff --git a/netobjdeepcopy.v11.suo b/netobjdeepcopy.v11.suo new file mode 100644 index 0000000..91c4146 Binary files /dev/null and b/netobjdeepcopy.v11.suo differ diff --git a/unittests/ObjectExtensionsTests.cs b/unittests/ObjectExtensionsTests.cs new file mode 100644 index 0000000..ec3c935 --- /dev/null +++ b/unittests/ObjectExtensionsTests.cs @@ -0,0 +1,94 @@ +#region + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +#endregion + +namespace unittests +{ + [TestClass] + public class ObjectExtensionsTests + { + private class MySingleObject + { + public string One; + private int two; + + public int Two + { + get { return two; } + set { two = value; } + } + } + + private class MyNestedObject + { + public MySingleObject Single; + public string Meta; + } + + [TestMethod] + public void Copy_XElementWithChildren() + { + XElement el = XElement.Parse(@" + + hi + hello + "); + XElement copied = el.Copy(); + + var children = copied.Elements("child").ToList(); + Assert.AreEqual(2, children.Count); + Assert.AreEqual("wow", children[0].Attribute("attrib").Value); + Assert.AreEqual("hi", children[0].Value); + + Assert.AreEqual("yeah", children[1].Attribute("attrib").Value); + Assert.AreEqual("hello", children[1].Value); + } + + [TestMethod] + public void Copy_CopiesNestedObject() + { + MyNestedObject copied = + new MyNestedObject() {Meta = "metadata", Single = new MySingleObject() {One = "single_one"}}.Copy(); + + Assert.AreEqual("metadata", copied.Meta); + Assert.AreEqual("single_one", copied.Single.One); + } + + [TestMethod] + public void Copy_CopiesEnumerables() + { + IList list = new List() + { + new MySingleObject() {One = "1"}, + new MySingleObject() {One = "2"} + }; + IList copied = list.Copy(); + + Assert.AreEqual(2, copied.Count); + Assert.AreEqual("1", list[0].One); + Assert.AreEqual("2", list[1].One); + } + + [TestMethod] + public void Copy_CopiesSingleObject() + { + MySingleObject copied = new MySingleObject() {One = "one", Two = 2}.Copy(); + + Assert.AreEqual("one", copied.One); + Assert.AreEqual(2, copied.Two); + } + + [TestMethod] + public void Copy_CopiesSingleBuiltInObjects() + { + Assert.AreEqual("hello there", "hello there".Copy()); + Assert.AreEqual(123, 123.Copy()); + } + } +} \ No newline at end of file diff --git a/unittests/Properties/AssemblyInfo.cs b/unittests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5c9077d --- /dev/null +++ b/unittests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("unittests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Cegekanv")] +[assembly: AssemblyProduct("unittests")] +[assembly: AssemblyCopyright("Copyright © Cegekanv 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("ee1ceb32-5ed9-4c74-a402-2cb2d71450f0")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/unittests/unittests.csproj b/unittests/unittests.csproj new file mode 100644 index 0000000..9b8cffe --- /dev/null +++ b/unittests/unittests.csproj @@ -0,0 +1,91 @@ + + + + Debug + AnyCPU + {F3B0CDAD-046C-4023-B980-C5EA0FCE9D9B} + Library + Properties + unittests + unittests + v4.5 + 512 + {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages + False + UnitTest + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {7900459d-f2f7-461f-948a-ffe4eeff6148} + netobjdeepcopy + + + + + + + False + + + False + + + False + + + False + + + + + + + + \ No newline at end of file