Пример #1
0
        internal void AutoComplete(JsonToken tokenBeingWritten)
        {
            JsonWriter.State state = JsonWriter.StateArray[(int)tokenBeingWritten][(int)this._currentState];
            if (state == JsonWriter.State.Error)
            {
                throw JsonWriterException.Create(this,
                                                 "Token {0} in state {1} would result in an invalid JSON object.".FormatWith(
                                                     (IFormatProvider)CultureInfo.InvariantCulture, (object)tokenBeingWritten.ToString(),
                                                     (object)this._currentState.ToString()), (Exception)null);
            }
            if ((this._currentState == JsonWriter.State.Object || this._currentState == JsonWriter.State.Array ||
                 this._currentState == JsonWriter.State.Constructor) && tokenBeingWritten != JsonToken.Comment)
            {
                this.WriteValueDelimiter();
            }
            if (this._formatting == Formatting.Indented)
            {
                if (this._currentState == JsonWriter.State.Property)
                {
                    this.WriteIndentSpace();
                }
                if (this._currentState == JsonWriter.State.Array || this._currentState == JsonWriter.State.ArrayStart ||
                    (this._currentState == JsonWriter.State.Constructor ||
                     this._currentState == JsonWriter.State.ConstructorStart) || tokenBeingWritten == JsonToken.PropertyName &&
                    this._currentState != JsonWriter.State.Start)
                {
                    this.WriteIndent();
                }
            }

            this._currentState = state;
        }
Пример #2
0
        private void AutoCompleteClose(JsonContainerType type)
        {
            int num1 = 0;

            if (this._currentPosition.Type == type)
            {
                num1 = 1;
            }
            else
            {
                int num2 = this.Top - 2;
                for (int index = num2; index >= 0; --index)
                {
                    if (this._stack[num2 - index].Type == type)
                    {
                        num1 = index + 2;
                        break;
                    }
                }
            }
            if (num1 == 0)
            {
                throw JsonWriterException.Create(this, "No token to close.", (Exception)null);
            }
            for (int index = 0; index < num1; ++index)
            {
                JsonToken closeTokenForType = this.GetCloseTokenForType(this.Pop());
                if (this._currentState == JsonWriter.State.Property)
                {
                    this.WriteNull();
                }
                if (this._formatting == Formatting.Indented && this._currentState != JsonWriter.State.ObjectStart && this._currentState != JsonWriter.State.ArrayStart)
                {
                    this.WriteIndent();
                }
                this.WriteEnd(closeTokenForType);
                JsonContainerType jsonContainerType = this.Peek();
                switch (jsonContainerType)
                {
                case JsonContainerType.None:
                    this._currentState = JsonWriter.State.Start;
                    break;

                case JsonContainerType.Object:
                    this._currentState = JsonWriter.State.Object;
                    break;

                case JsonContainerType.Array:
                    this._currentState = JsonWriter.State.Array;
                    break;

                case JsonContainerType.Constructor:
                    this._currentState = JsonWriter.State.Array;
                    break;

                default:
                    throw JsonWriterException.Create(this, "Unknown JsonType: " + (object)jsonContainerType, (Exception)null);
                }
            }
        }
Пример #3
0
        private void UpdateCurrentState()
        {
            JsonContainerType jsonContainerType = this.Peek();

            switch (jsonContainerType)
            {
            case JsonContainerType.None:
                this._currentState = JsonWriter.State.Start;
                break;

            case JsonContainerType.Object:
                this._currentState = JsonWriter.State.Object;
                break;

            case JsonContainerType.Array:
                this._currentState = JsonWriter.State.Array;
                break;

            case JsonContainerType.Constructor:
                this._currentState = JsonWriter.State.Array;
                break;

            default:
                throw JsonWriterException.Create(this, "Unknown JsonType: " + (object)jsonContainerType, (Exception)null);
            }
        }
Пример #4
0
 protected JsonWriter()
 {
     this._currentState         = JsonWriter.State.Start;
     this._formatting           = Formatting.None;
     this._dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
     this.CloseOutput           = true;
     this.AutoCompleteOnClose   = true;
 }
Пример #5
0
 protected JsonWriter()
 {
     this._stack                = new List <JsonPosition>(4);
     this._currentState         = JsonWriter.State.Start;
     this._formatting           = Formatting.None;
     this._dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
     this.CloseOutput           = true;
 }
Пример #6
0
 protected JsonWriter()
 {
     this._stack = new List <JTokenType>(8);
     this._stack.Add(JTokenType.None);
     this._currentState = JsonWriter.State.Start;
     this._formatting   = Formatting.None;
     this.CloseOutput   = true;
 }
Пример #7
0
        internal void AutoComplete(JsonToken tokenBeingWritten)
        {
            int num;

            switch (tokenBeingWritten)
            {
            case JsonToken.Integer:
            case JsonToken.Float:
            case JsonToken.String:
            case JsonToken.Boolean:
            case JsonToken.Null:
            case JsonToken.Undefined:
            case JsonToken.Date:
            case JsonToken.Bytes:
                num = 7;
                goto IL_49;

            case JsonToken.EndObject:
            case JsonToken.EndArray:
            case JsonToken.EndConstructor:
IL_3B:
                num = (int)tokenBeingWritten;
                goto IL_49;
            }
            goto IL_3B;
IL_49:
            JsonWriter.State state = JsonWriter.stateArray[num][(int)this._currentState];
            if (state == JsonWriter.State.Error)
            {
                throw new JsonWriterException("Token {0} in state {1} would result in an invalid JavaScript object.".FormatWith(CultureInfo.get_InvariantCulture(), new object[]
                {
                    tokenBeingWritten.ToString(),
                    this._currentState.ToString()
                }));
            }
            if ((this._currentState == JsonWriter.State.Object || this._currentState == JsonWriter.State.Array || this._currentState == JsonWriter.State.Constructor) && tokenBeingWritten != JsonToken.Comment)
            {
                this.WriteValueDelimiter();
            }
            else if (this._currentState == JsonWriter.State.Property && this._formatting == Formatting.Indented)
            {
                this.WriteIndentSpace();
            }
            WriteState writeState = this.WriteState;

            if ((tokenBeingWritten == JsonToken.PropertyName && writeState != WriteState.Start) || writeState == WriteState.Array || writeState == WriteState.Constructor)
            {
                this.WriteIndent();
            }
            this._currentState = state;
        }
Пример #8
0
        private void AutoCompleteClose(JsonToken tokenBeingClosed)
        {
            int num = 0;

            for (int i = 0; i < this._top; i++)
            {
                int num2 = this._top - i;
                if (this._stack.get_Item(num2) == this.GetTypeForCloseToken(tokenBeingClosed))
                {
                    num = i + 1;
                    break;
                }
            }
            if (num == 0)
            {
                throw new JsonWriterException("No token to close.");
            }
            for (int j = 0; j < num; j++)
            {
                JsonToken closeTokenForType = this.GetCloseTokenForType(this.Pop());
                if (this._currentState != JsonWriter.State.ObjectStart && this._currentState != JsonWriter.State.ArrayStart)
                {
                    this.WriteIndent();
                }
                this.WriteEnd(closeTokenForType);
            }
            JTokenType jTokenType = this.Peek();

            switch (jTokenType)
            {
            case JTokenType.None:
                this._currentState = JsonWriter.State.Start;
                break;

            case JTokenType.Object:
                this._currentState = JsonWriter.State.Object;
                break;

            case JTokenType.Array:
                this._currentState = JsonWriter.State.Array;
                break;

            case JTokenType.Constructor:
                this._currentState = JsonWriter.State.Array;
                break;

            default:
                throw new JsonWriterException("Unknown JsonType: " + jTokenType);
            }
        }
Пример #9
0
 internal void AutoComplete(JsonToken tokenBeingWritten)
 {
   JsonWriter.State state = JsonWriter.StateArray[(int) tokenBeingWritten][(int) this._currentState];
   if (state == JsonWriter.State.Error)
     throw JsonWriterException.Create(this, StringUtils.FormatWith("Token {0} in state {1} would result in an invalid JSON object.", (IFormatProvider) CultureInfo.InvariantCulture, (object) ((object) tokenBeingWritten).ToString(), (object) ((object) this._currentState).ToString()), (Exception) null);
   if ((this._currentState == JsonWriter.State.Object || this._currentState == JsonWriter.State.Array || this._currentState == JsonWriter.State.Constructor) && tokenBeingWritten != JsonToken.Comment)
     this.WriteValueDelimiter();
   else if (this._currentState == JsonWriter.State.Property && this._formatting == Formatting.Indented)
     this.WriteIndentSpace();
   if (this._formatting == Formatting.Indented)
   {
     WriteState writeState = this.WriteState;
     if (tokenBeingWritten == JsonToken.PropertyName && writeState != WriteState.Start || (writeState == WriteState.Array || writeState == WriteState.Constructor))
       this.WriteIndent();
   }
   this._currentState = state;
 }
Пример #10
0
 private void AutoCompleteClose(JsonContainerType type)
 {
   int num1 = 0;
   if (this._currentPosition.Type == type)
   {
     num1 = 1;
   }
   else
   {
     int num2 = this.Top - 2;
     for (int index = num2; index >= 0; --index)
     {
       if (this._stack[num2 - index].Type == type)
       {
         num1 = index + 2;
         break;
       }
     }
   }
   if (num1 == 0)
     throw JsonWriterException.Create(this, "No token to close.", (Exception) null);
   for (int index = 0; index < num1; ++index)
   {
     JsonToken closeTokenForType = this.GetCloseTokenForType(this.Pop());
     if (this._currentState == JsonWriter.State.Property)
       this.WriteNull();
     if (this._formatting == Formatting.Indented && this._currentState != JsonWriter.State.ObjectStart && this._currentState != JsonWriter.State.ArrayStart)
       this.WriteIndent();
     this.WriteEnd(closeTokenForType);
     JsonContainerType jsonContainerType = this.Peek();
     switch (jsonContainerType)
     {
       case JsonContainerType.None:
         this._currentState = JsonWriter.State.Start;
         break;
       case JsonContainerType.Object:
         this._currentState = JsonWriter.State.Object;
         break;
       case JsonContainerType.Array:
         this._currentState = JsonWriter.State.Array;
         break;
       case JsonContainerType.Constructor:
         this._currentState = JsonWriter.State.Array;
         break;
       default:
         throw JsonWriterException.Create(this, "Unknown JsonType: " + (object) jsonContainerType, (Exception) null);
     }
   }
 }
Пример #11
0
 protected JsonWriter()
 {
   this._stack = new List<JsonPosition>(4);
   this._currentState = JsonWriter.State.Start;
   this._formatting = Formatting.None;
   this._dateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
   this.CloseOutput = true;
 }
Пример #12
0
 // Token: 0x06000117 RID: 279
 // RVA: 0x0002ABF0 File Offset: 0x00028DF0
 internal void AutoComplete(JsonToken tokenBeingWritten)
 {
     JsonWriter.State state = JsonWriter.StateArray[(int)tokenBeingWritten][(int)this._currentState];
     if (state == JsonWriter.State.Error)
     {
         throw JsonWriterException.Create(this, StringUtils.FormatWith("Token {0} in state {1} would result in an invalid JSON object.", CultureInfo.InvariantCulture, tokenBeingWritten.ToString(), this._currentState.ToString()), null);
     }
     if ((this._currentState == JsonWriter.State.Object || this._currentState == JsonWriter.State.Array || this._currentState == JsonWriter.State.Constructor) && tokenBeingWritten != JsonToken.Comment)
     {
         this.WriteValueDelimiter();
     }
     if (this._formatting == Formatting.Indented)
     {
         if (this._currentState == JsonWriter.State.Property)
         {
             this.WriteIndentSpace();
         }
         if (this._currentState == JsonWriter.State.Array || this._currentState == JsonWriter.State.ArrayStart || this._currentState == JsonWriter.State.Constructor || this._currentState == JsonWriter.State.ConstructorStart || (tokenBeingWritten == JsonToken.PropertyName && this._currentState != JsonWriter.State.Start))
         {
             this.WriteIndent();
         }
     }
     this._currentState = state;
 }