public static ComplexObject Create() { ComplexObject simpleObject = new ComplexObject() { NestedObject = SimpleObject.Create(), NestedEmptyObject = EmptyObject.Create(), NestedNullObject = null, ArrayOfObjects = new SimpleObject[] { SimpleObject.Create(), null, SimpleObject.Create() }, EmptyArrayOfObjects = new SimpleObject[] { }, NullArrayOfObjects = null, NestedArrayOfInts = new int[][] { new int[] { 1, 2, 3 }, null, new int[] { }, new int[] { -1, -2, -3 } }, NestedEmptyArrayOfInts = new int[][] { }, NestedNullArrayOfInts = null, NestedArrayOfStrings = new string[][] { new string[] { "String1", "String2", "String3" }, new string[] {}, null, }, NestedEmptyArrayOfStrings = new string[][] { }, NestedNullArrayOfStrings = null, NestedArrayOfObjects = new SimpleObject[][] { new SimpleObject[] { SimpleObject.Create(), null, SimpleObject.Create() }, new SimpleObject[] { }, null, }, NestedEmptyArrayOfObjects = new SimpleObject[][] { }, NestedNullArrayOfObjects = null, }; return simpleObject; }
public static ComplexObject ReadFrom( IObjectReader reader) { ComplexObject complexObject = null; if (reader.ReadStartObject()) { complexObject = new ComplexObject(); int memberKey; while (reader.ReadNextMemberKey()) { memberKey = reader.MemberKey; if (memberKey == MemberKey.NestedObject) { complexObject.NestedObject = SimpleObject.ReadFrom(reader); } if (memberKey == MemberKey.NestedEmptyObject) { complexObject.NestedEmptyObject = EmptyObject.ReadFrom(reader); } if (memberKey == MemberKey.NestedNullObject) { complexObject.NestedNullObject = SimpleObject.ReadFrom(reader); } else if (memberKey == MemberKey.ArrayOfObjects) { complexObject.ArrayOfObjects = ReadArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.EmptyArrayOfObjects) { complexObject.EmptyArrayOfObjects = ReadArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NullArrayOfObjects) { complexObject.NullArrayOfObjects = ReadArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NestedArrayOfInts) { complexObject.NestedArrayOfInts = ReadNestedArrayOfInts(reader); } else if (memberKey == MemberKey.NestedEmptyArrayOfInts) { complexObject.NestedEmptyArrayOfInts = ReadNestedArrayOfInts(reader); } else if (memberKey == MemberKey.NestedNullArrayOfInts) { complexObject.NestedNullArrayOfInts = ReadNestedArrayOfInts(reader); } else if (memberKey == MemberKey.NestedArrayOfStrings) { complexObject.NestedArrayOfStrings = ReadNestedArrayOfStrings(reader); } else if (memberKey == MemberKey.NestedEmptyArrayOfStrings) { complexObject.NestedEmptyArrayOfStrings = ReadNestedArrayOfStrings(reader); } else if (memberKey == MemberKey.NestedNullArrayOfStrings) { complexObject.NestedNullArrayOfStrings = ReadNestedArrayOfStrings(reader); } else if (memberKey == MemberKey.NestedArrayOfObjects) { complexObject.NestedArrayOfObjects = ReadNestedArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NestedEmptyArrayOfObjects) { complexObject.NestedEmptyArrayOfObjects = ReadNestedArrayOfSimpleObjects(reader); } else if (memberKey == MemberKey.NestedNullArrayOfObjects) { complexObject.NestedNullArrayOfObjects = ReadNestedArrayOfSimpleObjects(reader); } //else //{ // Debug.WriteLine("Skipping member key {0}", memberKey); //} } reader.ReadEndObject(); } return complexObject; }
public void VerifyIsEqual( ComplexObject other) { // TODO }
public static void WriteTo( IObjectWriter writer, ComplexObject complexObject) { if (null == complexObject) { writer.WriteNullValue(); return; } writer.WriteStartObject(); // Nested object writer.WriteStartMember(MemberKey.NestedObject); SimpleObject.WriteTo(writer, complexObject.NestedObject); writer.WriteEndMember(); // Nested object (write-only) writer.WriteStartMember(MemberKey.WriteOnlyNestedObject); SimpleObject.WriteTo(writer, complexObject.NestedObject); writer.WriteEndMember(); // Nested empty object writer.WriteStartMember(MemberKey.NestedEmptyObject); EmptyObject.WriteTo(writer, complexObject.NestedEmptyObject); writer.WriteEndMember(); // Nested empty object (write-only) writer.WriteStartMember(MemberKey.WriteOnlyNestedEmptyObject); SimpleObject.WriteTo(writer, complexObject.NestedNullObject); writer.WriteEndMember(); // Nested null object writer.WriteStartMember(MemberKey.NestedNullObject); SimpleObject.WriteTo(writer, complexObject.NestedNullObject); writer.WriteEndMember(); // Nested null object (write-only) writer.WriteStartMember(MemberKey.WriteOnlyNestedNullObject); SimpleObject.WriteTo(writer, complexObject.NestedNullObject); writer.WriteEndMember(); // Array of objects WriteMember(writer, MemberKey.ArrayOfObjects, complexObject.ArrayOfObjects); WriteMember(writer, MemberKey.WriteOnlyArrayOfObjects, complexObject.ArrayOfObjects); // Empty array of objects WriteMember(writer, MemberKey.EmptyArrayOfObjects, complexObject.EmptyArrayOfObjects); WriteMember(writer, MemberKey.WriteOnlyEmptyArrayOfObjects, complexObject.EmptyArrayOfObjects); // Null array of objects WriteMember(writer, MemberKey.NullArrayOfObjects, complexObject.NullArrayOfObjects); WriteMember(writer, MemberKey.WriteOnlyNullArrayOfObjects, complexObject.NullArrayOfObjects); // Nested array of ints WriteMember(writer, MemberKey.NestedArrayOfInts, complexObject.NestedArrayOfInts); WriteMember(writer, MemberKey.WriteOnlyNestedArrayOfInts, complexObject.NestedArrayOfInts); // Empty nested array of ints WriteMember(writer, MemberKey.NestedEmptyArrayOfInts, complexObject.NestedEmptyArrayOfInts); WriteMember(writer, MemberKey.WriteOnlyNestedEmptyArrayOfInts, complexObject.NestedEmptyArrayOfInts); // Null nested array of ints WriteMember(writer, MemberKey.NestedNullArrayOfInts, complexObject.NestedNullArrayOfInts); WriteMember(writer, MemberKey.WriteOnlyNestedNullArrayOfInts, complexObject.NestedNullArrayOfInts); // Nested array of strings WriteMember(writer, MemberKey.NestedArrayOfStrings, complexObject.NestedArrayOfStrings); WriteMember(writer, MemberKey.WriteOnlyNestedArrayOfStrings, complexObject.NestedArrayOfStrings); // Empty nested array of strings WriteMember(writer, MemberKey.NestedEmptyArrayOfStrings, complexObject.NestedEmptyArrayOfStrings); WriteMember(writer, MemberKey.WriteOnlyNestedEmptyArrayOfStrings, complexObject.NestedEmptyArrayOfStrings); // Null nested array of strings WriteMember(writer, MemberKey.NestedNullArrayOfStrings, complexObject.NestedNullArrayOfStrings); WriteMember(writer, MemberKey.WriteOnlyNestedNullArrayOfStrings, complexObject.NestedNullArrayOfStrings); // Nested array of objects WriteMember(writer, MemberKey.NestedArrayOfObjects, complexObject.NestedArrayOfObjects); WriteMember(writer, MemberKey.WriteOnlyNestedArrayOfObjects, complexObject.NestedArrayOfObjects); // Empty nested array of objects WriteMember(writer, MemberKey.NestedEmptyArrayOfObjects, complexObject.NestedEmptyArrayOfObjects); WriteMember(writer, MemberKey.WriteOnlyNestedEmptyArrayOfObjects, complexObject.NestedEmptyArrayOfObjects); // Null nested array of objects WriteMember(writer, MemberKey.NestedNullArrayOfObjects, complexObject.NestedNullArrayOfObjects); WriteMember(writer, MemberKey.WriteOnlyNestedNullArrayOfObjects, complexObject.NestedNullArrayOfObjects); writer.WriteEndObject(); }