本文整理汇总了C#中Serializer.Release方法的典型用法代码示例。如果您正苦于以下问题:C# Serializer.Release方法的具体用法?C# Serializer.Release怎么用?C# Serializer.Release使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serializer
的用法示例。
在下文中一共展示了Serializer.Release方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
}
示例2: TestSerializationDeserializationPrimitives
public void TestSerializationDeserializationPrimitives()
{
Serializer serializer = new Serializer();
serializer.Initialize();
TestPrimitives source = new TestPrimitives() {
b1 = byte.MinValue, b2 = byte.MaxValue, sb1 = sbyte.MinValue, sb2 = sbyte.MaxValue,
s1 = short.MinValue, s2 = short.MaxValue, us1 = ushort.MinValue, us2 = ushort.MaxValue,
i1 = int.MinValue, i2 = int.MaxValue, u1 = uint.MinValue, u2 = uint.MaxValue,
f = (float)System.Math.PI, d = System.Math.PI, c1 = char.MinValue, c2 = char.MaxValue, s = "foo" };
object intermediate = serializer.Serialize(source, true);
TestPrimitives result = (TestPrimitives) serializer.Deserialize(intermediate);
foreach (var member in TypeUtils.GetMembers(source)) {
object sobj = TypeUtils.GetValue(member, source);
object robj = TypeUtils.GetValue(member, result);
Assert.IsTrue(sobj.Equals(robj));
}
serializer.Release();
}
示例3: TestSerializationDeltaAndJSON
public void TestSerializationDeltaAndJSON()
{
Serializer serializer = new Serializer();
serializer.Initialize();
serializer.SkipDefaultsDuringSerialization = true;
Test source = new Test();
source.tstr = "Test String";
source.ti = 1;
source.td = 3.141;
source.tTypedList = new List<TestData> { new TestData { name = "wheat" }, new TestData { name = "bread" } };
source.tTestRecursive = new Test();
source.tTestRecursive.tstr = "Hello World!";
source.tTypedDictOfData = new Dictionary<string, TestData> { { "foo", new TestData { name = "wheat" } } };
Hashtable serialized = serializer.Serialize(source) as Hashtable;
Assert.IsNotNull(serialized);
string json = JSON.JsonEncode(serialized);
Assert.IsNotNull(json);
object unjson = JSON.JsonDecode(json);
Assert.IsNotNull(unjson);
Test result = serializer.Deserialize<Test>(unjson);
Assert.IsNotNull(result);
Assert.IsTrue(source.tstr == result.tstr);
Assert.IsTrue(source.td == result.td);
Assert.IsTrue(source.ti == result.ti);
Assert.IsTrue(source.tTestRecursive.tstr == result.tTestRecursive.tstr);
Assert.IsTrue(source.tTypedDictOfData["foo"].name == result.tTypedDictOfData["foo"].name);
Assert.IsTrue(source.tTypedDictOfData["foo"].buy == result.tTypedDictOfData["foo"].buy);
serializer.Release();
}
示例4: TestSerializationDelta
public void TestSerializationDelta()
{
Serializer serializer = new Serializer();
serializer.Initialize();
serializer.SkipDefaultsDuringSerialization = true;
Test source = new Test();
source.tstr = "Test String";
source.tTypedList = new List<TestData> { new TestData { name = "wheat" }, new TestData { name = "bread" } };
source.tTestRecursive = new Test();
source.tTestRecursive.tstr = "Hello World!";
source.tTypedDictOfData = new Dictionary<string, TestData> { { "foo", new TestData { name = "wheat" } } };
Hashtable serialized = serializer.Serialize(source) as Hashtable;
Assert.IsTrue(serialized["tstr"] as String == "Test String");
Assert.IsTrue(serialized["td"] == null);
Assert.IsTrue(serialized["ti"] == null);
Assert.IsTrue(serialized["te"] == null);
Assert.IsTrue((serialized["tTestRecursive"] as Hashtable)["tstr"] as String == "Hello World!");
Assert.IsTrue(((serialized["tTypedDictOfData"] as Hashtable)["foo"] as Hashtable)["name"] as string == "wheat");
Test result = serializer.Deserialize<Test>(serialized);
Assert.IsTrue(source.tstr == result.tstr);
Assert.IsTrue(source.td == result.td);
Assert.IsTrue(source.tTestRecursive.tstr == result.tTestRecursive.tstr);
Assert.IsTrue(source.tTypedDictOfData["foo"].name == result.tTypedDictOfData["foo"].name);
serializer.Release();
}
示例5: TestSerialization
public void TestSerialization()
{
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 TestSubData { name = "bread", subname = "wheat" } };
source.tTestRecursive = new Test();
source.tTestRecursive.tstr = "Hello World!";
source.tStruct.i = 42;
object result = serializer.Serialize(source);
Assert.IsTrue(result is Hashtable);
Assert.IsTrue(((Hashtable)result).Keys.Count == (skipDefaults ? 11 : 14));
Assert.IsTrue((string)((Hashtable)result)["tstr"] == "Test String");
Assert.IsTrue((int)((Hashtable)result)["ti"] == 1);
Assert.IsTrue((double)((Hashtable)result)["td"] == 3.141);
Assert.IsTrue((int)((Hashtable)result)["te"] == 1); // enum gets serialized as its numeric value
string json = JSON.JsonEncode(result);
Assert.IsNotNull(json);
serializer.Release();
}
}
示例6: TestDeserialization
public void TestDeserialization()
{
Serializer serializer = new Serializer();
serializer.Initialize();
Hashtable jsonobj = JSON.JsonDecode(json) as Hashtable;
Test target = serializer.Deserialize<Test>(jsonobj);
Assert.IsTrue(target.ti == 1);
Assert.IsTrue(target.td == 3.141);
Assert.IsTrue(target.tstr == "This is a test string");
Assert.IsTrue(target.te == TestEnum.ValueOfOne);
Assert.IsTrue(target.tHashtable.Keys.Count == 3);
Assert.IsTrue(target.tHashtable["foo"] as String == "bar");
Assert.IsTrue(target.tHashtable["instance"] is TestData);
Assert.IsTrue((target.tHashtable["instance"] as TestData).name == "foo");
Assert.IsTrue(target.tTypedDictionary.Keys.Count == 3);
Assert.IsTrue(target.tTypedDictionary["a"] == 1);
Assert.IsTrue(target.tTypedDictionary["b"] == 2);
Assert.IsTrue(target.tTypedDictionary["c"] == 3.1);
Assert.IsTrue(target.tTypedDictOfData.Keys.Count == 1);
Assert.IsTrue(target.tTypedDictOfData["foo"].name == "wheat");
Assert.IsTrue(target.tArrayList.Count == 4);
Assert.IsTrue(target.tArrayList[2] as String == "foo");
Assert.IsTrue(target.tTypedList.Count == 3);
Assert.IsTrue(target.tTypedList[0].name == "wheat");
Assert.IsTrue(target.tTypedList[0].buy == 10);
Assert.IsTrue(target.tTypedList[0].sell);
Assert.IsTrue(target.tStruct.i == 123);
Assert.IsTrue(target.tStruct.j == 0);
Assert.IsTrue(target.tTestRecursive.ti == 4);
Assert.IsTrue(target.tTestRecursiveExplicit is Test);
Assert.IsTrue((target.tTestRecursiveExplicit as Test).ti == 42);
serializer.Release();
}