public void ToStringMethod()
{
var obj =
new ToStringObj
{
Bool = true,
Char = 'a',
Byte = 1,
SByte = -2,
Short = 3,
UShort = 4,
Int = 5,
UInt = 6,
Long = 7,
ULong = 8,
Float = 9,
Double = 10,
Decimal = 11,
String = "Hello \"World\" Test",
NBool = null,
NChar = 'b',
NByte = null,
NSByte = -3,
NShort = null,
NUShort = 5,
NInt = null,
NUInt = 7,
NLong = null,
NULong = 9,
NFloat = null,
NDouble = 11,
NDecimal = null,
Guid = Guid.Parse("B94F865C-82F5-4A60-BD14-20BD4CEA5BB8"),
NGuid = null,
TimeSpan = new TimeSpan(1, 2, 3, 4),
NTimeSpan = new TimeSpan(5, 6, 7, 8),
DateTime = DateTime.Parse("1989-11-08 20:17:00"),
NDateTime = null,
AbsoluteUri = new Uri("http://example.com/example"),
//RelativeUri = new Uri("/example/path", UriKind.Relative),
DictIntInt =
new Dictionary<int, int>
{
{ 1, 2 },
{ 3, 4 },
{ 5, 6 }
},
ListInt = new List<int> { 3, 1, 4, 1, 5, 9, 2, 6 },
DictDoubleListInt = new Dictionary<double,List<int>> { { 1.038, new List<int> { 8,6,7,6,5,3,0,9 } }, { 1.618, new List<int> { 1, 1, 2, 6 } } },
DictListIntDouble = new Dictionary<List<int>,double> { { new List<int> { 1, 0, 3, 8 }, 8675309 }, { new List<int> { 1, 6, 1, 8 }, 1126 } }
};
var clone = obj.Clone();
obj.RecursiveRef = clone;
obj.ListToStringObj = new List<ToStringObj> { clone, clone, clone };
obj.DictIntToStringObj = new Dictionary<int, ToStringObj> { { 100, clone } };
obj.DictToStringObjToStringObj = new Dictionary<ToStringObj, ToStringObj> { { clone, clone } };
obj.DictToStringObjInt = new Dictionary<ToStringObj, int> { { clone, 200 } };
var bytes = Serializer.Serialize(obj);
var dyn = Serializer.Deserialize(bytes);
var str = dyn.ToString();
Assert.AreEqual(
"{\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: \r\n {\r\n {\r\n 100\r\n ->\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n }\r\n }\r\n },\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: \r\n {\r\n {\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n }\r\n ->\r\n 200\r\n }\r\n },\r\n DictToStringObjToStringObj: \r\n {\r\n {\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n }\r\n ->\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n }\r\n }\r\n },\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: \r\n [\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n },\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n },\r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n }\r\n ],\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: \r\n {\r\n AbsoluteUri: http://example.com/example,\r\n Bool: True,\r\n Byte: 1,\r\n Char: a,\r\n DateTime: 1989-11-08 20:17:00Z,\r\n Decimal: 11,\r\n DictDoubleListInt: \r\n {\r\n {1.038 -> [8, 6, 7, 6, 5, 3, 0, 9]},\r\n {1.618 -> [1, 1, 2, 6]}\r\n },\r\n DictIntInt: \r\n {\r\n {1 -> 2},\r\n {3 -> 4},\r\n {5 -> 6}\r\n },\r\n DictIntToStringObj: null,\r\n DictListIntDouble: \r\n {\r\n {[1, 0, 3, 8] -> 8675309},\r\n {[1, 6, 1, 8] -> 1126}\r\n },\r\n DictToStringObjInt: null,\r\n DictToStringObjToStringObj: null,\r\n Double: 10,\r\n Float: 9,\r\n Guid: b94f865c-82f5-4a60-bd14-20bd4cea5bb8,\r\n Int: 5,\r\n ListInt: [3, 1, 4, 1, 5, 9, 2, 6],\r\n ListToStringObj: null,\r\n Long: 7,\r\n NBool: null,\r\n NByte: null,\r\n NChar: b,\r\n NDateTime: null,\r\n NDecimal: null,\r\n NDouble: 11,\r\n NFloat: null,\r\n NGuid: null,\r\n NInt: null,\r\n NLong: null,\r\n NSByte: -3,\r\n NShort: null,\r\n NTimeSpan: 5.06:07:08,\r\n NUInt: 7,\r\n NULong: 9,\r\n NUShort: 5,\r\n RecursiveRef: null,\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n },\r\n RelativeUri: null,\r\n SByte: -2,\r\n Short: 3,\r\n String: \"Hello \\\"World\\\" Test\",\r\n TimeSpan: 1.02:03:04,\r\n UInt: 6,\r\n ULong: 8,\r\n UShort: 4\r\n}",
str
);
}