本文整理汇总了C#中Serializer.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.Clone方法的具体用法?C# Serializer.Clone怎么用?C# Serializer.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.Clone方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestClone
public void TestClone()
{
foreach (bool skipDefaults in new bool[] { true, false }) {
Serializer serializer = new Serializer();
serializer.Initialize();
serializer.SkipDefaultsDuringSerialization = skipDefaults;
Test source = new Test();
source.tstr = "Test String";
source.ti = 1;
source.td = 3.141;
source.te = TestEnum.ValueOfOne;
source.tHashtable = new Hashtable { { 1, 2 }, { "foo", new TestData { name = "bar" } } };
source.tTypedDictionary = new Dictionary<string, double> { { "foo", 1 }, { "bar", 2 } };
source.tTypedDictOfData = new Dictionary<string, TestData> { { "foo", new TestData { name = "wheat" } } };
source.tArrayList = new ArrayList { 1, 2, "foo", true, new TestData { name = "wheat" } };
source.tTypedList = new List<TestData> { new TestData { name = "wheat" }, new TestData { name = "bread" } };
source.tTestRecursive = new Test();
source.tTestRecursive.tstr = "Hello World!";
Test target = serializer.Clone(source);
Assert.IsTrue(target != source);
Assert.IsTrue(source.tstr == target.tstr);
Assert.IsTrue(source.ti == target.ti);
Assert.IsTrue(source.td == target.td);
Assert.IsTrue(source.te == target.te);
Assert.IsTrue(source.tHashtable != target.tHashtable);
Assert.IsTrue(source.tHashtable.Count == target.tHashtable.Count);
Assert.IsTrue((int)(source.tHashtable[1]) == (int)(target.tHashtable[1]));
Assert.IsTrue(((TestData)(source.tHashtable["foo"])).name == ((TestData)(target.tHashtable["foo"])).name);
Assert.IsTrue(source.tArrayList.Count == target.tArrayList.Count);
Assert.IsTrue(source.tTypedList.Count == target.tTypedList.Count);
Assert.IsTrue(source.tTypedList[0].name == target.tTypedList[0].name);
serializer.Release();
}
}