public static void WriteTo(
                IObjectWriter writer,
                JsonNetSimpleObject obj)
            {
                if (null == obj)
                {
                    writer.WriteNullValue();
                    return;
                }

                writer.WriteStartObject();

                writer.WriteMember(1, obj.Id);

                writer.WriteMember(2, obj.Name);

                writer.WriteMember(3, obj.Address);

                writer.WriteMember(4, obj.Scores);

                writer.WriteEndObject();
            }
        public static void SerializePerson(Person person, IObjectWriter writer)
        {
            if (person == null)
            {
                writer.WriteNullValue();
            }
            else
            {
                writer.WriteStartObject();

                writer.WriteMember(1, person.Id);
                writer.WriteMember(2, person.Name);
                writer.WriteMember(3, person.Scores);

                writer.WriteEndObject();
            }
        }
Example #3
0
        public static void WriteTo(
            IObjectWriter writer,
            SimpleObject simpleObject)
        {
            if (null == simpleObject)
            {
                writer.WriteNullValue();
                return;
            }

            writer.WriteStartObject();

            // String
            writer.WriteMember(MemberKey.StringValue, simpleObject.StringValue);
            writer.WriteMember(MemberKey.WriteOnlyStringValue, simpleObject.StringValue);

            // Empty String
            writer.WriteMember(MemberKey.StringEmptyValue, simpleObject.StringEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyStringEmptyValue, simpleObject.StringEmptyValue);

            // Null String
            writer.WriteMember(MemberKey.StringNullValue, simpleObject.StringNullValue);
            writer.WriteMember(MemberKey.WriteOnlyStringNullValue, simpleObject.StringNullValue);

            // Byte[]
            writer.WriteMember(MemberKey.ByteArrayValue, simpleObject.ByteArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyByteArrayValue, simpleObject.ByteArrayValue);

            // Empty Byte[]
            writer.WriteMember(MemberKey.ByteArrayEmptyValue, simpleObject.ByteArrayEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyByteArrayEmptyValue, simpleObject.ByteArrayEmptyValue);

            // Null Byte[]
            writer.WriteMember(MemberKey.ByteArrayNullValue, simpleObject.ByteArrayNullValue);
            writer.WriteMember(MemberKey.WriteOnlyByteArrayNullValue, simpleObject.ByteArrayNullValue);

            // 0 Int
            writer.WriteMember(MemberKey.Int32ZeroValue, simpleObject.Int32ZeroValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ZeroValue, simpleObject.Int32ZeroValue);

            // Min Int
            writer.WriteMember(MemberKey.Int32MinValue, simpleObject.Int32MinValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32MinValue, simpleObject.Int32MinValue);

            // Max Int
            writer.WriteMember(MemberKey.Int32MaxValue, simpleObject.Int32MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32MaxValue, simpleObject.Int32MaxValue);

            // Min UInt32
            writer.WriteMember(MemberKey.UInt32MinValue, simpleObject.UInt32MinValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt32MinValue, simpleObject.UInt32MinValue);

            // Max UInt32
            writer.WriteMember(MemberKey.UInt32MaxValue, simpleObject.UInt32MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt32MaxValue, simpleObject.UInt32MaxValue);

            // Single
            writer.WriteMember(MemberKey.SingleValue, simpleObject.SingleValue);
            writer.WriteMember(MemberKey.WriteOnlySingleValue, simpleObject.SingleValue);

            // Min Single
            writer.WriteMember(MemberKey.SingleMinValue, simpleObject.SingleMinValue);
            writer.WriteMember(MemberKey.WriteOnlySingleMinValue, simpleObject.SingleMinValue);

            // Max Single
            writer.WriteMember(MemberKey.SingleMaxValue, simpleObject.SingleMaxValue);
            writer.WriteMember(MemberKey.WriteOnlySingleMaxValue, simpleObject.SingleMaxValue);

            // Int32 Array
            writer.WriteMember(MemberKey.Int32ArrayValue, simpleObject.Int32ArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ArrayValue, simpleObject.Int32ArrayValue);

            // Empty Int32 Array
            writer.WriteMember(MemberKey.Int32ArrayEmptyValue, simpleObject.Int32ArrayEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ArrayEmptyValue, simpleObject.Int32ArrayEmptyValue);

            // Null Int32 Array
            writer.WriteMember(MemberKey.Int32ArrayNullValue, simpleObject.Int32ArrayNullValue);
            writer.WriteMember(MemberKey.WriteOnlyInt32ArrayNullValue, simpleObject.Int32ArrayNullValue);

            // String Array
            writer.WriteMember(MemberKey.StringArrayValue, simpleObject.StringArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyStringArrayValue, simpleObject.StringArrayValue);

            // Empty String Array
            writer.WriteMember(MemberKey.StringArrayEmptyValue, simpleObject.StringArrayEmptyValue);
            writer.WriteMember(MemberKey.WriteOnlyStringArrayEmptyValue, simpleObject.StringArrayEmptyValue);

            // Null String Array
            writer.WriteMember(MemberKey.StringArrayNullValue, simpleObject.StringArrayNullValue);
            writer.WriteMember(MemberKey.WriteOnlyStringArrayNullValue, simpleObject.StringArrayNullValue);

            // String with escapes
            writer.WriteMember(MemberKey.StringWithEscapesValue, simpleObject.StringWithEscapesValue);
            writer.WriteMember(MemberKey.WriteOnlyStringWithEscapesValue, simpleObject.StringWithEscapesValue);

            // String with surrogate pairs
            writer.WriteMember(MemberKey.StringWithSurrogatePairsValue, simpleObject.StringWithSurrogatePairsValue);
            writer.WriteMember(MemberKey.WriteOnlyStringWithSurrogatePairsValue, simpleObject.StringWithSurrogatePairsValue);

            // Double
            writer.WriteMember(MemberKey.DoubleValue, simpleObject.DoubleValue);
            writer.WriteMember(MemberKey.WriteOnlyDoubleValue, simpleObject.DoubleValue);

            // Min double
            writer.WriteMember(MemberKey.DoubleMinValue, simpleObject.DoubleMinValue);
            writer.WriteMember(MemberKey.WriteOnlyDoubleMinValue, simpleObject.DoubleMinValue);

            // Max double
            writer.WriteMember(MemberKey.DoubleMaxValue, simpleObject.DoubleMaxValue);
            writer.WriteMember(MemberKey.WriteOnlyDoubleMaxValue, simpleObject.DoubleMaxValue);

            // Int64
            writer.WriteMember(MemberKey.Int64ZeroValue, simpleObject.Int64ZeroValue);
            writer.WriteMember(MemberKey.WriteOnlyInt64ZeroValue, simpleObject.Int64ZeroValue);

            // Min Int64
            writer.WriteMember(MemberKey.Int64MinValue, simpleObject.Int64MinValue);
            writer.WriteMember(MemberKey.WriteOnlyInt64MinValue, simpleObject.Int64MinValue);

            // Max Int64
            writer.WriteMember(MemberKey.Int64MaxValue, simpleObject.Int64MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyInt64MaxValue, simpleObject.Int64MaxValue);

            // UInt64
            writer.WriteMember(MemberKey.UInt64ZeroValue, simpleObject.UInt64ZeroValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt64ZeroValue, simpleObject.UInt64ZeroValue);

            // Min UInt64
            writer.WriteMember(MemberKey.UInt64MinValue, simpleObject.UInt64MinValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt64MinValue, simpleObject.UInt64MinValue);

            // Max UInt64
            writer.WriteMember(MemberKey.UInt64MaxValue, simpleObject.UInt64MaxValue);
            writer.WriteMember(MemberKey.WriteOnlyUInt64MaxValue, simpleObject.UInt64MaxValue);

            // Boolean true
            writer.WriteMember(MemberKey.BooleanTrueValue, simpleObject.BooleanTrueValue);
            writer.WriteMember(MemberKey.WriteOnlyBooleanTrueValue, simpleObject.BooleanTrueValue);

            // Boolean false
            writer.WriteMember(MemberKey.BooleanFalseValue, simpleObject.BooleanFalseValue);
            writer.WriteMember(MemberKey.WriteOnlyBooleanFalseValue, simpleObject.BooleanFalseValue);

            // Boolean array
            writer.WriteMember(MemberKey.BooleanArrayValue, simpleObject.BooleanArrayValue);
            writer.WriteMember(MemberKey.WriteOnlyBooleanArrayValue, simpleObject.BooleanArrayValue);

            writer.WriteEndObject();
        }