Пример #1
0
        internal virtual void SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
        {
            ValidationUtils.ArgumentNotNull(jsonWriter, nameof(jsonWriter));

            // set serialization options onto writer
            Formatting?previousFormatting = null;

            if (_formatting != null && jsonWriter.Formatting != _formatting)
            {
                previousFormatting    = jsonWriter.Formatting;
                jsonWriter.Formatting = _formatting.GetValueOrDefault();
            }

            DateFormatHandling?previousDateFormatHandling = null;

            if (_dateFormatHandling != null && jsonWriter.DateFormatHandling != _dateFormatHandling)
            {
                previousDateFormatHandling    = jsonWriter.DateFormatHandling;
                jsonWriter.DateFormatHandling = _dateFormatHandling.GetValueOrDefault();
            }

            DateTimeZoneHandling?previousDateTimeZoneHandling = null;

            if (_dateTimeZoneHandling != null && jsonWriter.DateTimeZoneHandling != _dateTimeZoneHandling)
            {
                previousDateTimeZoneHandling    = jsonWriter.DateTimeZoneHandling;
                jsonWriter.DateTimeZoneHandling = _dateTimeZoneHandling.GetValueOrDefault();
            }

            FloatFormatHandling?previousFloatFormatHandling = null;

            if (_floatFormatHandling != null && jsonWriter.FloatFormatHandling != _floatFormatHandling)
            {
                previousFloatFormatHandling    = jsonWriter.FloatFormatHandling;
                jsonWriter.FloatFormatHandling = _floatFormatHandling.GetValueOrDefault();
            }

            StringEscapeHandling?previousStringEscapeHandling = null;

            if (_stringEscapeHandling != null && jsonWriter.StringEscapeHandling != _stringEscapeHandling)
            {
                previousStringEscapeHandling    = jsonWriter.StringEscapeHandling;
                jsonWriter.StringEscapeHandling = _stringEscapeHandling.GetValueOrDefault();
            }

            CultureInfo previousCulture = null;

            if (_culture != null && !_culture.Equals(jsonWriter.Culture))
            {
                previousCulture    = jsonWriter.Culture;
                jsonWriter.Culture = _culture;
            }

            string previousDateFormatString = null;

            if (_dateFormatStringSet && jsonWriter.DateFormatString != _dateFormatString)
            {
                previousDateFormatString    = jsonWriter.DateFormatString;
                jsonWriter.DateFormatString = _dateFormatString;
            }

            TraceJsonWriter traceJsonWriter = (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
                ? new TraceJsonWriter(jsonWriter)
                : null;

            JsonSerializerInternalWriter serializerWriter = new JsonSerializerInternalWriter(this);

            serializerWriter.Serialize(traceJsonWriter ?? jsonWriter, value, objectType);

            if (traceJsonWriter != null)
            {
                TraceWriter.Trace(TraceLevel.Verbose, traceJsonWriter.GetSerializedJsonMessage(), null);
            }

            // reset writer back to previous options
            if (previousFormatting != null)
            {
                jsonWriter.Formatting = previousFormatting.GetValueOrDefault();
            }
            if (previousDateFormatHandling != null)
            {
                jsonWriter.DateFormatHandling = previousDateFormatHandling.GetValueOrDefault();
            }
            if (previousDateTimeZoneHandling != null)
            {
                jsonWriter.DateTimeZoneHandling = previousDateTimeZoneHandling.GetValueOrDefault();
            }
            if (previousFloatFormatHandling != null)
            {
                jsonWriter.FloatFormatHandling = previousFloatFormatHandling.GetValueOrDefault();
            }
            if (previousStringEscapeHandling != null)
            {
                jsonWriter.StringEscapeHandling = previousStringEscapeHandling.GetValueOrDefault();
            }
            if (_dateFormatStringSet)
            {
                jsonWriter.DateFormatString = previousDateFormatString;
            }
            if (previousCulture != null)
            {
                jsonWriter.Culture = previousCulture;
            }
        }
        internal virtual void SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
        {
            TraceJsonWriter traceJsonWriter;

            ValidationUtils.ArgumentNotNull(jsonWriter, "jsonWriter");
            Newtonsoft.Json.Formatting?nullable = null;
            if (this._formatting.HasValue)
            {
                Newtonsoft.Json.Formatting formatting = jsonWriter.Formatting;
                Newtonsoft.Json.Formatting?nullable1  = this._formatting;
                if ((formatting == nullable1.GetValueOrDefault() ? !nullable1.HasValue : true))
                {
                    nullable = new Newtonsoft.Json.Formatting?(jsonWriter.Formatting);
                    jsonWriter.Formatting = this._formatting.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.DateFormatHandling?nullable2 = null;
            if (this._dateFormatHandling.HasValue)
            {
                Newtonsoft.Json.DateFormatHandling dateFormatHandling = jsonWriter.DateFormatHandling;
                Newtonsoft.Json.DateFormatHandling?nullable3          = this._dateFormatHandling;
                if ((dateFormatHandling == nullable3.GetValueOrDefault() ? !nullable3.HasValue : true))
                {
                    nullable2 = new Newtonsoft.Json.DateFormatHandling?(jsonWriter.DateFormatHandling);
                    jsonWriter.DateFormatHandling = this._dateFormatHandling.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.DateTimeZoneHandling?nullable4 = null;
            if (this._dateTimeZoneHandling.HasValue)
            {
                Newtonsoft.Json.DateTimeZoneHandling dateTimeZoneHandling = jsonWriter.DateTimeZoneHandling;
                Newtonsoft.Json.DateTimeZoneHandling?nullable5            = this._dateTimeZoneHandling;
                if ((dateTimeZoneHandling == nullable5.GetValueOrDefault() ? !nullable5.HasValue : true))
                {
                    nullable4 = new Newtonsoft.Json.DateTimeZoneHandling?(jsonWriter.DateTimeZoneHandling);
                    jsonWriter.DateTimeZoneHandling = this._dateTimeZoneHandling.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.FloatFormatHandling?nullable6 = null;
            if (this._floatFormatHandling.HasValue)
            {
                Newtonsoft.Json.FloatFormatHandling floatFormatHandling = jsonWriter.FloatFormatHandling;
                Newtonsoft.Json.FloatFormatHandling?nullable7           = this._floatFormatHandling;
                if ((floatFormatHandling == nullable7.GetValueOrDefault() ? !nullable7.HasValue : true))
                {
                    nullable6 = new Newtonsoft.Json.FloatFormatHandling?(jsonWriter.FloatFormatHandling);
                    jsonWriter.FloatFormatHandling = this._floatFormatHandling.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.StringEscapeHandling?nullable8 = null;
            if (this._stringEscapeHandling.HasValue)
            {
                Newtonsoft.Json.StringEscapeHandling stringEscapeHandling = jsonWriter.StringEscapeHandling;
                Newtonsoft.Json.StringEscapeHandling?nullable9            = this._stringEscapeHandling;
                if ((stringEscapeHandling == nullable9.GetValueOrDefault() ? !nullable9.HasValue : true))
                {
                    nullable8 = new Newtonsoft.Json.StringEscapeHandling?(jsonWriter.StringEscapeHandling);
                    jsonWriter.StringEscapeHandling = this._stringEscapeHandling.GetValueOrDefault();
                }
            }
            CultureInfo culture = null;

            if (this._culture != null && !this._culture.Equals(jsonWriter.Culture))
            {
                culture            = jsonWriter.Culture;
                jsonWriter.Culture = this._culture;
            }
            string dateFormatString = null;

            if (this._dateFormatStringSet && jsonWriter.DateFormatString != this._dateFormatString)
            {
                dateFormatString            = jsonWriter.DateFormatString;
                jsonWriter.DateFormatString = this._dateFormatString;
            }
            if (this.TraceWriter == null || this.TraceWriter.LevelFilter < TraceLevel.Verbose)
            {
                traceJsonWriter = null;
            }
            else
            {
                traceJsonWriter = new TraceJsonWriter(jsonWriter);
            }
            TraceJsonWriter traceJsonWriter1 = traceJsonWriter;
            JsonSerializerInternalWriter jsonSerializerInternalWriter = new JsonSerializerInternalWriter(this);
            JsonWriter jsonWriter1 = traceJsonWriter1;

            if (jsonWriter1 == null)
            {
                jsonWriter1 = jsonWriter;
            }
            jsonSerializerInternalWriter.Serialize(jsonWriter1, value, objectType);
            if (traceJsonWriter1 != null)
            {
                this.TraceWriter.Trace(TraceLevel.Verbose, traceJsonWriter1.GetSerializedJsonMessage(), null);
            }
            if (nullable.HasValue)
            {
                jsonWriter.Formatting = nullable.GetValueOrDefault();
            }
            if (nullable2.HasValue)
            {
                jsonWriter.DateFormatHandling = nullable2.GetValueOrDefault();
            }
            if (nullable4.HasValue)
            {
                jsonWriter.DateTimeZoneHandling = nullable4.GetValueOrDefault();
            }
            if (nullable6.HasValue)
            {
                jsonWriter.FloatFormatHandling = nullable6.GetValueOrDefault();
            }
            if (nullable8.HasValue)
            {
                jsonWriter.StringEscapeHandling = nullable8.GetValueOrDefault();
            }
            if (this._dateFormatStringSet)
            {
                jsonWriter.DateFormatString = dateFormatString;
            }
            if (culture != null)
            {
                jsonWriter.Culture = culture;
            }
        }
Пример #3
0
        internal virtual void SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
        {
            ValidationUtils.ArgumentNotNull((object)jsonWriter, nameof(jsonWriter));
            Formatting?nullable1 = new Formatting?();

            if (this._formatting.HasValue)
            {
                int        formatting1    = (int)jsonWriter.Formatting;
                Formatting?formatting2    = this._formatting;
                int        valueOrDefault = (int)formatting2.GetValueOrDefault();
                if ((formatting1 == valueOrDefault ? (!formatting2.HasValue ? 1 : 0) : 1) != 0)
                {
                    nullable1             = new Formatting?(jsonWriter.Formatting);
                    jsonWriter.Formatting = this._formatting.GetValueOrDefault();
                }
            }
            DateFormatHandling?nullable2 = new DateFormatHandling?();

            if (this._dateFormatHandling.HasValue)
            {
                int dateFormatHandling1 = (int)jsonWriter.DateFormatHandling;
                DateFormatHandling?dateFormatHandling2 = this._dateFormatHandling;
                int valueOrDefault = (int)dateFormatHandling2.GetValueOrDefault();
                if ((dateFormatHandling1 == valueOrDefault ? (!dateFormatHandling2.HasValue ? 1 : 0) : 1) != 0)
                {
                    nullable2 = new DateFormatHandling?(jsonWriter.DateFormatHandling);
                    jsonWriter.DateFormatHandling = this._dateFormatHandling.GetValueOrDefault();
                }
            }
            DateTimeZoneHandling?nullable3 = new DateTimeZoneHandling?();

            if (this._dateTimeZoneHandling.HasValue)
            {
                int timeZoneHandling1 = (int)jsonWriter.DateTimeZoneHandling;
                DateTimeZoneHandling?timeZoneHandling2 = this._dateTimeZoneHandling;
                int valueOrDefault = (int)timeZoneHandling2.GetValueOrDefault();
                if ((timeZoneHandling1 == valueOrDefault ? (!timeZoneHandling2.HasValue ? 1 : 0) : 1) != 0)
                {
                    nullable3 = new DateTimeZoneHandling?(jsonWriter.DateTimeZoneHandling);
                    jsonWriter.DateTimeZoneHandling = this._dateTimeZoneHandling.GetValueOrDefault();
                }
            }
            FloatFormatHandling?nullable4 = new FloatFormatHandling?();

            if (this._floatFormatHandling.HasValue)
            {
                int floatFormatHandling1 = (int)jsonWriter.FloatFormatHandling;
                FloatFormatHandling?floatFormatHandling2 = this._floatFormatHandling;
                int valueOrDefault = (int)floatFormatHandling2.GetValueOrDefault();
                if ((floatFormatHandling1 == valueOrDefault ? (!floatFormatHandling2.HasValue ? 1 : 0) : 1) != 0)
                {
                    nullable4 = new FloatFormatHandling?(jsonWriter.FloatFormatHandling);
                    jsonWriter.FloatFormatHandling = this._floatFormatHandling.GetValueOrDefault();
                }
            }
            StringEscapeHandling?nullable5 = new StringEscapeHandling?();

            if (this._stringEscapeHandling.HasValue)
            {
                int stringEscapeHandling1 = (int)jsonWriter.StringEscapeHandling;
                StringEscapeHandling?stringEscapeHandling2 = this._stringEscapeHandling;
                int valueOrDefault = (int)stringEscapeHandling2.GetValueOrDefault();
                if ((stringEscapeHandling1 == valueOrDefault ? (!stringEscapeHandling2.HasValue ? 1 : 0) : 1) != 0)
                {
                    nullable5 = new StringEscapeHandling?(jsonWriter.StringEscapeHandling);
                    jsonWriter.StringEscapeHandling = this._stringEscapeHandling.GetValueOrDefault();
                }
            }
            CultureInfo cultureInfo = (CultureInfo)null;

            if (this._culture != null && !this._culture.Equals((object)jsonWriter.Culture))
            {
                cultureInfo        = jsonWriter.Culture;
                jsonWriter.Culture = this._culture;
            }
            string str = (string)null;

            if (this._dateFormatStringSet && jsonWriter.DateFormatString != this._dateFormatString)
            {
                str = jsonWriter.DateFormatString;
                jsonWriter.DateFormatString = this._dateFormatString;
            }
            TraceJsonWriter traceJsonWriter = this.TraceWriter == null || this.TraceWriter.LevelFilter < TraceLevel.Verbose ? (TraceJsonWriter)null : new TraceJsonWriter(jsonWriter);

            new JsonSerializerInternalWriter(this).Serialize((JsonWriter)traceJsonWriter ?? jsonWriter, value, objectType);
            if (traceJsonWriter != null)
            {
                this.TraceWriter.Trace_(TraceLevel.Verbose, traceJsonWriter.GetSerializedJsonMessage(), (Exception)null);
            }
            if (nullable1.HasValue)
            {
                jsonWriter.Formatting = nullable1.GetValueOrDefault();
            }
            if (nullable2.HasValue)
            {
                jsonWriter.DateFormatHandling = nullable2.GetValueOrDefault();
            }
            if (nullable3.HasValue)
            {
                jsonWriter.DateTimeZoneHandling = nullable3.GetValueOrDefault();
            }
            if (nullable4.HasValue)
            {
                jsonWriter.FloatFormatHandling = nullable4.GetValueOrDefault();
            }
            if (nullable5.HasValue)
            {
                jsonWriter.StringEscapeHandling = nullable5.GetValueOrDefault();
            }
            if (this._dateFormatStringSet)
            {
                jsonWriter.DateFormatString = str;
            }
            if (cultureInfo == null)
            {
                return;
            }
            jsonWriter.Culture = cultureInfo;
        }
Пример #4
0
        public void TraceJsonWriterTest()
        {
            StringWriter    sw          = new StringWriter(CultureInfo.InvariantCulture);
            JsonTextWriter  w           = new JsonTextWriter(sw);
            TraceJsonWriter traceWriter = new TraceJsonWriter(w);

            traceWriter.WriteStartObject();
            traceWriter.WritePropertyName("Array");
            traceWriter.WriteStartArray();
            traceWriter.WriteValue("String!");
            traceWriter.WriteValue(new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc));
            traceWriter.WriteValue(new DateTimeOffset(2000, 12, 12, 12, 12, 12, TimeSpan.FromHours(2)));
            traceWriter.WriteValue(1.1f);
            traceWriter.WriteValue(1.1d);
            traceWriter.WriteValue(1.1m);
            traceWriter.WriteValue(1);
            traceWriter.WriteValue((char)'!');
            traceWriter.WriteValue((short)1);
            traceWriter.WriteValue((ushort)1);
            traceWriter.WriteValue((int)1);
            traceWriter.WriteValue((uint)1);
            traceWriter.WriteValue((sbyte)1);
            traceWriter.WriteValue((byte)1);
            traceWriter.WriteValue((long)1);
            traceWriter.WriteValue((ulong)1);
            traceWriter.WriteValue((bool)true);

            traceWriter.WriteValue((DateTime?)new DateTime(2000, 12, 12, 12, 12, 12, DateTimeKind.Utc));
            traceWriter.WriteValue((DateTimeOffset?)new DateTimeOffset(2000, 12, 12, 12, 12, 12, TimeSpan.FromHours(2)));
            traceWriter.WriteValue((float?)1.1f);
            traceWriter.WriteValue((double?)1.1d);
            traceWriter.WriteValue((decimal?)1.1m);
            traceWriter.WriteValue((int?)1);
            traceWriter.WriteValue((char?)'!');
            traceWriter.WriteValue((short?)1);
            traceWriter.WriteValue((ushort?)1);
            traceWriter.WriteValue((int?)1);
            traceWriter.WriteValue((uint?)1);
            traceWriter.WriteValue((sbyte?)1);
            traceWriter.WriteValue((byte?)1);
            traceWriter.WriteValue((long?)1);
            traceWriter.WriteValue((ulong?)1);
            traceWriter.WriteValue((bool?)true);
            traceWriter.WriteValue(BigInteger.Parse("9999999990000000000000000000000000000000000"));

            traceWriter.WriteValue((object)true);
            traceWriter.WriteValue(TimeSpan.FromMinutes(1));
            traceWriter.WriteValue(Guid.Empty);
            traceWriter.WriteValue(new Uri("http://www.google.com/"));
            traceWriter.WriteValue(Encoding.UTF8.GetBytes("String!"));
            traceWriter.WriteRawValue("[1],");
            traceWriter.WriteRaw("[1]");
            traceWriter.WriteNull();
            traceWriter.WriteUndefined();
            traceWriter.WriteStartConstructor("ctor");
            traceWriter.WriteValue(1);
            traceWriter.WriteEndConstructor();
            traceWriter.WriteComment("A comment");
            traceWriter.WriteWhitespace("       ");
            traceWriter.WriteEnd();
            traceWriter.WriteEndObject();
            traceWriter.Flush();
            traceWriter.Close();

            string json = @"{
  ""Array"": [
    ""String!"",
    ""2000-12-12T12:12:12Z"",
    ""2000-12-12T12:12:12+02:00"",
    1.1,
    1.1,
    1.1,
    1,
    ""!"",
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    true,
    ""2000-12-12T12:12:12Z"",
    ""2000-12-12T12:12:12+02:00"",
    1.1,
    1.1,
    1.1,
    1,
    ""!"",
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    true,
    9999999990000000000000000000000000000000000,
    true,
    true,
    ""00:01:00"",
    ""00000000-0000-0000-0000-000000000000"",
    ""http://www.google.com/"",
    ""U3RyaW5nIQ=="",
    [1],[1],[1],
    null,
    undefined,
    new ctor(
      1
    )
    /*A comment*/       
  ]
}";

            StringAssert.AreEqual("Serialized JSON: " + Environment.NewLine + json, traceWriter.GetSerializedJsonMessage());
        }
Пример #5
0
        internal virtual void SerializeInternal([Nullable(1)] JsonWriter jsonWriter, object value, Type objectType)
        {
            ValidationUtils.ArgumentNotNull(jsonWriter, "jsonWriter");
            Formatting?formatting = null;

            if (this._formatting != null)
            {
                Formatting formatting2 = jsonWriter.Formatting;
                Formatting?formatting3 = this._formatting;
                if (!(formatting2 == formatting3.GetValueOrDefault() & formatting3 != null))
                {
                    formatting            = new Formatting?(jsonWriter.Formatting);
                    jsonWriter.Formatting = this._formatting.GetValueOrDefault();
                }
            }
            DateFormatHandling?dateFormatHandling = null;

            if (this._dateFormatHandling != null)
            {
                DateFormatHandling dateFormatHandling2 = jsonWriter.DateFormatHandling;
                DateFormatHandling?dateFormatHandling3 = this._dateFormatHandling;
                if (!(dateFormatHandling2 == dateFormatHandling3.GetValueOrDefault() & dateFormatHandling3 != null))
                {
                    dateFormatHandling            = new DateFormatHandling?(jsonWriter.DateFormatHandling);
                    jsonWriter.DateFormatHandling = this._dateFormatHandling.GetValueOrDefault();
                }
            }
            DateTimeZoneHandling?dateTimeZoneHandling = null;

            if (this._dateTimeZoneHandling != null)
            {
                DateTimeZoneHandling dateTimeZoneHandling2 = jsonWriter.DateTimeZoneHandling;
                DateTimeZoneHandling?dateTimeZoneHandling3 = this._dateTimeZoneHandling;
                if (!(dateTimeZoneHandling2 == dateTimeZoneHandling3.GetValueOrDefault() & dateTimeZoneHandling3 != null))
                {
                    dateTimeZoneHandling            = new DateTimeZoneHandling?(jsonWriter.DateTimeZoneHandling);
                    jsonWriter.DateTimeZoneHandling = this._dateTimeZoneHandling.GetValueOrDefault();
                }
            }
            FloatFormatHandling?floatFormatHandling = null;

            if (this._floatFormatHandling != null)
            {
                FloatFormatHandling floatFormatHandling2 = jsonWriter.FloatFormatHandling;
                FloatFormatHandling?floatFormatHandling3 = this._floatFormatHandling;
                if (!(floatFormatHandling2 == floatFormatHandling3.GetValueOrDefault() & floatFormatHandling3 != null))
                {
                    floatFormatHandling            = new FloatFormatHandling?(jsonWriter.FloatFormatHandling);
                    jsonWriter.FloatFormatHandling = this._floatFormatHandling.GetValueOrDefault();
                }
            }
            StringEscapeHandling?stringEscapeHandling = null;

            if (this._stringEscapeHandling != null)
            {
                StringEscapeHandling stringEscapeHandling2 = jsonWriter.StringEscapeHandling;
                StringEscapeHandling?stringEscapeHandling3 = this._stringEscapeHandling;
                if (!(stringEscapeHandling2 == stringEscapeHandling3.GetValueOrDefault() & stringEscapeHandling3 != null))
                {
                    stringEscapeHandling            = new StringEscapeHandling?(jsonWriter.StringEscapeHandling);
                    jsonWriter.StringEscapeHandling = this._stringEscapeHandling.GetValueOrDefault();
                }
            }
            CultureInfo cultureInfo = null;

            if (this._culture != null && !this._culture.Equals(jsonWriter.Culture))
            {
                cultureInfo        = jsonWriter.Culture;
                jsonWriter.Culture = this._culture;
            }
            string dateFormatString = null;

            if (this._dateFormatStringSet && jsonWriter.DateFormatString != this._dateFormatString)
            {
                dateFormatString            = jsonWriter.DateFormatString;
                jsonWriter.DateFormatString = this._dateFormatString;
            }
            TraceJsonWriter traceJsonWriter = (this.TraceWriter != null && this.TraceWriter.LevelFilter >= TraceLevel.Verbose) ? new TraceJsonWriter(jsonWriter) : null;

            new JsonSerializerInternalWriter(this).Serialize(traceJsonWriter ?? jsonWriter, value, objectType);
            if (traceJsonWriter != null)
            {
                this.TraceWriter.Trace(TraceLevel.Verbose, traceJsonWriter.GetSerializedJsonMessage(), null);
            }
            if (formatting != null)
            {
                jsonWriter.Formatting = formatting.GetValueOrDefault();
            }
            if (dateFormatHandling != null)
            {
                jsonWriter.DateFormatHandling = dateFormatHandling.GetValueOrDefault();
            }
            if (dateTimeZoneHandling != null)
            {
                jsonWriter.DateTimeZoneHandling = dateTimeZoneHandling.GetValueOrDefault();
            }
            if (floatFormatHandling != null)
            {
                jsonWriter.FloatFormatHandling = floatFormatHandling.GetValueOrDefault();
            }
            if (stringEscapeHandling != null)
            {
                jsonWriter.StringEscapeHandling = stringEscapeHandling.GetValueOrDefault();
            }
            if (this._dateFormatStringSet)
            {
                jsonWriter.DateFormatString = dateFormatString;
            }
            if (cultureInfo != null)
            {
                jsonWriter.Culture = cultureInfo;
            }
        }
Пример #6
0
        internal virtual void SerializeInternal(JsonWriter jsonWriter, object value, Type objectType)
        {
            ValidationUtils.ArgumentNotNull(jsonWriter, "jsonWriter");
            Newtonsoft.Json.Formatting?nullable = null;
            if (this._formatting.HasValue)
            {
                Newtonsoft.Json.Formatting?nullable2 = this._formatting;
                if ((jsonWriter.Formatting == ((Newtonsoft.Json.Formatting)nullable2.GetValueOrDefault())) ? !nullable2.HasValue : true)
                {
                    nullable = new Newtonsoft.Json.Formatting?(jsonWriter.Formatting);
                    jsonWriter.Formatting = this._formatting.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.DateFormatHandling?nullable3 = null;
            if (this._dateFormatHandling.HasValue)
            {
                Newtonsoft.Json.DateFormatHandling?nullable4 = this._dateFormatHandling;
                if ((jsonWriter.DateFormatHandling == ((Newtonsoft.Json.DateFormatHandling)nullable4.GetValueOrDefault())) ? !nullable4.HasValue : true)
                {
                    nullable3 = new Newtonsoft.Json.DateFormatHandling?(jsonWriter.DateFormatHandling);
                    jsonWriter.DateFormatHandling = this._dateFormatHandling.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.DateTimeZoneHandling?nullable5 = null;
            if (this._dateTimeZoneHandling.HasValue)
            {
                Newtonsoft.Json.DateTimeZoneHandling?nullable6 = this._dateTimeZoneHandling;
                if ((jsonWriter.DateTimeZoneHandling == ((Newtonsoft.Json.DateTimeZoneHandling)nullable6.GetValueOrDefault())) ? !nullable6.HasValue : true)
                {
                    nullable5 = new Newtonsoft.Json.DateTimeZoneHandling?(jsonWriter.DateTimeZoneHandling);
                    jsonWriter.DateTimeZoneHandling = this._dateTimeZoneHandling.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.FloatFormatHandling?nullable7 = null;
            if (this._floatFormatHandling.HasValue)
            {
                Newtonsoft.Json.FloatFormatHandling?nullable8 = this._floatFormatHandling;
                if ((jsonWriter.FloatFormatHandling == ((Newtonsoft.Json.FloatFormatHandling)nullable8.GetValueOrDefault())) ? !nullable8.HasValue : true)
                {
                    nullable7 = new Newtonsoft.Json.FloatFormatHandling?(jsonWriter.FloatFormatHandling);
                    jsonWriter.FloatFormatHandling = this._floatFormatHandling.GetValueOrDefault();
                }
            }
            Newtonsoft.Json.StringEscapeHandling?nullable9 = null;
            if (this._stringEscapeHandling.HasValue)
            {
                Newtonsoft.Json.StringEscapeHandling?nullable10 = this._stringEscapeHandling;
                if ((jsonWriter.StringEscapeHandling == ((Newtonsoft.Json.StringEscapeHandling)nullable10.GetValueOrDefault())) ? !nullable10.HasValue : true)
                {
                    nullable9 = new Newtonsoft.Json.StringEscapeHandling?(jsonWriter.StringEscapeHandling);
                    jsonWriter.StringEscapeHandling = this._stringEscapeHandling.GetValueOrDefault();
                }
            }
            CultureInfo culture = null;

            if ((this._culture != null) && !this._culture.Equals(jsonWriter.Culture))
            {
                culture            = jsonWriter.Culture;
                jsonWriter.Culture = this._culture;
            }
            string dateFormatString = null;

            if (this._dateFormatStringSet && (jsonWriter.DateFormatString != this._dateFormatString))
            {
                dateFormatString            = jsonWriter.DateFormatString;
                jsonWriter.DateFormatString = this._dateFormatString;
            }
            TraceJsonWriter writer = ((this.TraceWriter != null) && (this.TraceWriter.LevelFilter >= TraceLevel.Verbose)) ? new TraceJsonWriter(jsonWriter) : null;

            if (writer == null)
            {
            }
            new JsonSerializerInternalWriter(this).Serialize(jsonWriter, value, objectType);
            if (writer != null)
            {
                this.TraceWriter.Trace(TraceLevel.Verbose, writer.GetSerializedJsonMessage(), null);
            }
            if (nullable.HasValue)
            {
                jsonWriter.Formatting = nullable.GetValueOrDefault();
            }
            if (nullable3.HasValue)
            {
                jsonWriter.DateFormatHandling = nullable3.GetValueOrDefault();
            }
            if (nullable5.HasValue)
            {
                jsonWriter.DateTimeZoneHandling = nullable5.GetValueOrDefault();
            }
            if (nullable7.HasValue)
            {
                jsonWriter.FloatFormatHandling = nullable7.GetValueOrDefault();
            }
            if (nullable9.HasValue)
            {
                jsonWriter.StringEscapeHandling = nullable9.GetValueOrDefault();
            }
            if (this._dateFormatStringSet)
            {
                jsonWriter.DateFormatString = dateFormatString;
            }
            if (culture != null)
            {
                jsonWriter.Culture = culture;
            }
        }