示例#1
0
 protected JsonReader()
 {
     this._currentState         = JsonReader.State.Start;
     this._dateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.RoundtripKind;
     this._dateParseHandling    = Newtonsoft.Json.DateParseHandling.DateTime;
     this._floatParseHandling   = Newtonsoft.Json.FloatParseHandling.Double;
     this.CloseInput            = true;
 }
        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;
            }
        }
        private void SetupReader(JsonReader reader, out CultureInfo previousCulture, out Newtonsoft.Json.DateTimeZoneHandling?previousDateTimeZoneHandling, out Newtonsoft.Json.DateParseHandling?previousDateParseHandling, out Newtonsoft.Json.FloatParseHandling?previousFloatParseHandling, out int?previousMaxDepth, out string previousDateFormatString)
        {
            JsonTextReader          nameTable;
            DefaultContractResolver defaultContractResolver;

            if (this._culture == null || this._culture.Equals(reader.Culture))
            {
                previousCulture = null;
            }
            else
            {
                previousCulture = reader.Culture;
                reader.Culture  = this._culture;
            }
            if (this._dateTimeZoneHandling.HasValue)
            {
                Newtonsoft.Json.DateTimeZoneHandling dateTimeZoneHandling = reader.DateTimeZoneHandling;
                Newtonsoft.Json.DateTimeZoneHandling?nullable             = this._dateTimeZoneHandling;
                if ((dateTimeZoneHandling == nullable.GetValueOrDefault() ? nullable.HasValue : false))
                {
                    goto Label1;
                }
                previousDateTimeZoneHandling = new Newtonsoft.Json.DateTimeZoneHandling?(reader.DateTimeZoneHandling);
                reader.DateTimeZoneHandling  = this._dateTimeZoneHandling.GetValueOrDefault();
                goto Label0;
            }
Label1:
            previousDateTimeZoneHandling = null;
Label0:
            if (this._dateParseHandling.HasValue)
            {
                Newtonsoft.Json.DateParseHandling dateParseHandling = reader.DateParseHandling;
                Newtonsoft.Json.DateParseHandling?nullable1         = this._dateParseHandling;
                if ((dateParseHandling == nullable1.GetValueOrDefault() ? nullable1.HasValue : false))
                {
                    goto Label3;
                }
                previousDateParseHandling = new Newtonsoft.Json.DateParseHandling?(reader.DateParseHandling);
                reader.DateParseHandling  = this._dateParseHandling.GetValueOrDefault();
                goto Label2;
            }
Label3:
            previousDateParseHandling = null;
Label2:
            if (this._floatParseHandling.HasValue)
            {
                Newtonsoft.Json.FloatParseHandling floatParseHandling = reader.FloatParseHandling;
                Newtonsoft.Json.FloatParseHandling?nullable2          = this._floatParseHandling;
                if ((floatParseHandling == nullable2.GetValueOrDefault() ? nullable2.HasValue : false))
                {
                    goto Label5;
                }
                previousFloatParseHandling = new Newtonsoft.Json.FloatParseHandling?(reader.FloatParseHandling);
                reader.FloatParseHandling  = this._floatParseHandling.GetValueOrDefault();
                goto Label4;
            }
Label5:
            previousFloatParseHandling = null;
Label4:
            if (this._maxDepthSet)
            {
                int?maxDepth  = reader.MaxDepth;
                int?nullable3 = this._maxDepth;
                if ((maxDepth.GetValueOrDefault() == nullable3.GetValueOrDefault() ? maxDepth.HasValue == nullable3.HasValue : false))
                {
                    previousMaxDepth = null;
                    if (!this._dateFormatStringSet || !(reader.DateFormatString != this._dateFormatString))
                    {
                        previousDateFormatString = null;
                    }
                    else
                    {
                        previousDateFormatString = reader.DateFormatString;
                        reader.DateFormatString  = this._dateFormatString;
                    }
                    nameTable = reader as JsonTextReader;
                    if (nameTable != null)
                    {
                        defaultContractResolver = this._contractResolver as DefaultContractResolver;
                        if (defaultContractResolver != null)
                        {
                            nameTable.NameTable = defaultContractResolver.GetState().NameTable;
                        }
                    }
                    return;
                }
                previousMaxDepth = reader.MaxDepth;
                reader.MaxDepth  = this._maxDepth;
                if (!this._dateFormatStringSet || !(reader.DateFormatString != this._dateFormatString))
                {
                    previousDateFormatString = null;
                }
                else
                {
                    previousDateFormatString = reader.DateFormatString;
                    reader.DateFormatString  = this._dateFormatString;
                }
                nameTable = reader as JsonTextReader;
                if (nameTable != null)
                {
                    defaultContractResolver = this._contractResolver as DefaultContractResolver;
                    if (defaultContractResolver != null)
                    {
                        nameTable.NameTable = defaultContractResolver.GetState().NameTable;
                    }
                }
                return;
            }
            previousMaxDepth = null;
            if (!this._dateFormatStringSet || !(reader.DateFormatString != this._dateFormatString))
            {
                previousDateFormatString = null;
            }
            else
            {
                previousDateFormatString = reader.DateFormatString;
                reader.DateFormatString  = this._dateFormatString;
            }
            nameTable = reader as JsonTextReader;
            if (nameTable != null)
            {
                defaultContractResolver = this._contractResolver as DefaultContractResolver;
                if (defaultContractResolver != null)
                {
                    nameTable.NameTable = defaultContractResolver.GetState().NameTable;
                }
            }
        }