Example #1
0
        public void Serialize <T>(T value, TextWriter textWriter)
        {
            if (Options == JsonFormatterOptions.Default)
            {
                var serializer = new JsonDefaultSerializer(MaxDepth);

                ValueInterface <T> .Content.WriteValue(serializer, value);

                serializer.WriteTo(textWriter);
            }
            else
            {
                var serializer = new JsonSerializer(Options, MaxDepth);

                if ((Options & JsonFormatterOptions.Indented) != 0)
                {
                    serializer.indentedChars = IndentedChars;
                    serializer.lineBreak     = LineBreak;
                    serializer.middleChars   = MiddleChars;
                }

                ValueInterface <T> .Content.WriteValue(serializer, value);

                serializer.WriteTo(textWriter);
            }
        }
Example #2
0
        public static void SerializeObject <T>(T value, TextWriter textWriter)
        {
            var serializer = new JsonDefaultSerializer(DefaultMaxDepth);

            ValueInterface <T> .Content.WriteValue(serializer, value);

            serializer.WriteTo(textWriter);
        }
        public static void SerializeObject <T>(T value, TextWriter textWriter, JsonFormatterOptions options)
        {
            if ((options & ReferenceOptions) != 0)
            {
                var jsonSerializer = new JsonReferenceSerializer(options);

                jsonSerializer.textWriter = textWriter;

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.indentedChars = DefaultIndentedChars;
                    jsonSerializer.lineBreak     = DefaultLineBreak;
                    jsonSerializer.middleChars   = DefaultMiddleChars;
                }

                ValueInterface <T> .Content.WriteValue(jsonSerializer, value);

                jsonSerializer.WriteTo(textWriter);

                return;
            }

            if ((options & JsonFormatterOptions.PriorCheckReferences) != 0)
            {
                options ^= JsonFormatterOptions.PriorCheckReferences;
            }

            if (options == JsonFormatterOptions.Default)
            {
                var jsonSerializer = new JsonDefaultSerializer(DefaultMaxDepth);

                jsonSerializer.textWriter = textWriter;

                ValueInterface <T> .Content.WriteValue(jsonSerializer, value);

                jsonSerializer.WriteTo(textWriter);
            }
            else
            {
                var jsonSerializer = new JsonSerializer(options, DefaultMaxDepth);

                jsonSerializer.textWriter = textWriter;

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.indentedChars = DefaultIndentedChars;
                    jsonSerializer.lineBreak     = DefaultLineBreak;
                    jsonSerializer.middleChars   = DefaultMiddleChars;
                }

                ValueInterface <T> .Content.WriteValue(jsonSerializer, value);

                jsonSerializer.WriteTo(textWriter);
            }
        }
Example #4
0
        public void Serialize <T>(T value, TextWriter textWriter)
        {
            var options = Options;
            var id      = Id;

            if ((options & ReferenceOptions) != 0)
            {
                var jsonSerializer = new JsonReferenceSerializer(options);

                if (id != 0)
                {
                    jsonSerializer.id = id;
                }

                jsonSerializer.textWriter = textWriter;

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.indentedChars = IndentedChars;
                    jsonSerializer.lineBreak     = LineBreak;
                    jsonSerializer.middleChars   = MiddleChars;
                }

                ValueInterface <T> .Content.WriteValue(jsonSerializer, value);

                jsonSerializer.WriteTo(textWriter);

                return;
            }

            if ((options & JsonFormatterOptions.PriorCheckReferences) != 0)
            {
                options ^= JsonFormatterOptions.PriorCheckReferences;
            }

            if (options == JsonFormatterOptions.Default)
            {
                var jsonSerializer = new JsonDefaultSerializer(MaxDepth);

                if (id != 0)
                {
                    jsonSerializer.id = id;
                }

                jsonSerializer.textWriter = textWriter;

                ValueInterface <T> .Content.WriteValue(jsonSerializer, value);

                jsonSerializer.WriteTo(textWriter);
            }
            else
            {
                var jsonSerializer = new JsonSerializer(options, MaxDepth);

                if (id != 0)
                {
                    jsonSerializer.id = id;
                }

                jsonSerializer.textWriter = textWriter;

                if ((options & JsonFormatterOptions.Indented) != 0)
                {
                    jsonSerializer.indentedChars = IndentedChars;
                    jsonSerializer.lineBreak     = LineBreak;
                    jsonSerializer.middleChars   = MiddleChars;
                }

                ValueInterface <T> .Content.WriteValue(jsonSerializer, value);

                jsonSerializer.WriteTo(textWriter);
            }
        }