当前位置: 首页>>代码示例>>C#>>正文


C# Utilities.StringReference类代码示例

本文整理汇总了C#中Newtonsoft.Json.Utilities.StringReference的典型用法代码示例。如果您正苦于以下问题:C# StringReference类的具体用法?C# StringReference怎么用?C# StringReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StringReference类属于Newtonsoft.Json.Utilities命名空间,在下文中一共展示了StringReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseComment

 // Token: 0x0600071A RID: 1818
 // RVA: 0x0003A474 File Offset: 0x00038674
 private void ParseComment()
 {
     this._charPos++;
     if (!this.EnsureChars(1, false))
     {
         throw JsonReaderException.Create(this, "Unexpected end while parsing comment.");
     }
     bool flag;
     if (this._chars[this._charPos] == '*')
     {
         flag = false;
     }
     else
     {
         if (this._chars[this._charPos] != '/')
         {
             throw JsonReaderException.Create(this, StringUtils.FormatWith("Error parsing comment. Expected: *, got {0}.", CultureInfo.InvariantCulture, this._chars[this._charPos]));
         }
         flag = true;
     }
     this._charPos++;
     int charPos = this._charPos;
     bool flag2 = false;
     while (!flag2)
     {
         char c = this._chars[this._charPos];
         if (c <= '\n')
         {
             if (c != '\0')
             {
                 if (c == '\n')
                 {
                     if (flag)
                     {
                         this._stringReference = new StringReference(this._chars, charPos, this._charPos - charPos);
                         flag2 = true;
                     }
                     this.ProcessLineFeed();
                     continue;
                 }
             }
             else
             {
                 if (this._charsUsed != this._charPos)
                 {
                     this._charPos++;
                     continue;
                 }
                 if (this.ReadData(true) != 0)
                 {
                     continue;
                 }
                 if (flag)
                 {
                     this._stringReference = new StringReference(this._chars, charPos, this._charPos - charPos);
                     flag2 = true;
                     continue;
                 }
                 throw JsonReaderException.Create(this, "Unexpected end while parsing comment.");
             }
         }
         else
         {
             if (c == '\r')
             {
                 if (flag)
                 {
                     this._stringReference = new StringReference(this._chars, charPos, this._charPos - charPos);
                     flag2 = true;
                 }
                 this.ProcessCarriageReturn(true);
                 continue;
             }
             if (c == '*')
             {
                 this._charPos++;
                 if (!flag && this.EnsureChars(0, true) && this._chars[this._charPos] == '/')
                 {
                     this._stringReference = new StringReference(this._chars, charPos, this._charPos - charPos - 1);
                     this._charPos++;
                     flag2 = true;
                     continue;
                 }
                 continue;
             }
         }
         this._charPos++;
     }
     base.SetToken(JsonToken.Comment, this._stringReference.ToString());
     this.ClearRecentString();
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:93,代码来源:JsonTextReader.cs

示例2: ParseComment

    private void ParseComment()
    {
      // should have already parsed / character before reaching this method
      _charPos++;

      if (!EnsureChars(1, false) || _chars[_charPos] != '*')
        throw JsonReaderException.Create(this, "Error parsing comment. Expected: *, got {0}.".FormatWith(CultureInfo.InvariantCulture, _chars[_charPos]));
      else
        _charPos++;

      int initialPosition = _charPos;

      bool commentFinished = false;

      while (!commentFinished)
      {
        switch (_chars[_charPos])
        {
          case '\0':
            if (_charsUsed == _charPos)
            {
              if (ReadData(true) == 0)
                throw JsonReaderException.Create(this, "Unexpected end while parsing comment.");
            }
            else
            {
              _charPos++;
            }
            break;
          case '*':
            _charPos++;

            if (EnsureChars(0, true))
            {
              if (_chars[_charPos] == '/')
              {
                _stringReference = new StringReference(_chars, initialPosition, _charPos - initialPosition - 1);

                _charPos++;
                commentFinished = true;
              }
            }
            break;
          case StringUtils.CarriageReturn:
            ProcessCarriageReturn(true);
            break;
          case StringUtils.LineFeed:
            ProcessLineFeed();
            break;
          default:
            _charPos++;
            break;
        }
      }

      SetToken(JsonToken.Comment, _stringReference.ToString());

      ClearRecentString();
    }
开发者ID:DozenArts,项目名称:Newtonsoft.Json,代码行数:59,代码来源:JsonTextReader.cs

示例3: ClearRecentString

    private void ClearRecentString()
    {
      if (_buffer != null)
        _buffer.Position = 0;

      _stringReference = new StringReference();
    }
开发者ID:DozenArts,项目名称:Newtonsoft.Json,代码行数:7,代码来源:JsonTextReader.cs

示例4: TryReadOffset

        private static bool TryReadOffset(StringReference offsetText, int startIndex, out TimeSpan offset)
        {
            bool negative = (offsetText[startIndex] == '-');

            int hours;
            if (ConvertUtils.Int32TryParse(offsetText.Chars, startIndex + 1, 2, out hours) != ParseResult.Success)
            {
                offset = default(TimeSpan);
                return false;
            }

            int minutes = 0;
            if (offsetText.Length - startIndex > 5)
            {
                if (ConvertUtils.Int32TryParse(offsetText.Chars, startIndex + 3, 2, out minutes) != ParseResult.Success)
                {
                    offset = default(TimeSpan);
                    return false;
                }
            }

            offset = TimeSpan.FromHours(hours) + TimeSpan.FromMinutes(minutes);
            if (negative)
            {
                offset = offset.Negate();
            }

            return true;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:29,代码来源:DateTimeUtils.cs

示例5: ParseConstructor

    private void ParseConstructor()
    {
      if (MatchValueWithTrailingSeperator("new"))
      {
        EatWhitespace(false);

        int initialPosition = _charPos;
        int endPosition;

        while (true)
        {
          char currentChar = _chars[_charPos];
          if (currentChar == '\0')
          {
            if (_charsUsed == _charPos)
            {
              if (ReadData(true) == 0)
                throw JsonReaderException.Create(this, "Unexpected end while parsing constructor.");
            }
            else
            {
              endPosition = _charPos;
              _charPos++;
              break;
            }
          }
          else if (char.IsLetterOrDigit(currentChar))
          {
            _charPos++;
          }
          else if (currentChar == StringUtils.CarriageReturn)
          {
            endPosition = _charPos;
            ProcessCarriageReturn(true);
            break;
          }
          else if (currentChar == StringUtils.LineFeed)
          {
            endPosition = _charPos;
            ProcessLineFeed();
            break;
          }
          else if (char.IsWhiteSpace(currentChar))
          {
            endPosition = _charPos;
            _charPos++;
            break;
          }
          else if (currentChar == '(')
          {
            endPosition = _charPos;
            break;
          }
          else
          {
            throw JsonReaderException.Create(this, "Unexpected character while parsing constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
          }
        }

        _stringReference = new StringReference(_chars, initialPosition, endPosition - initialPosition);
        string constructorName = _stringReference.ToString();

        EatWhitespace(false);

        if (_chars[_charPos] != '(')
          throw JsonReaderException.Create(this, "Unexpected character while parsing constructor: {0}.".FormatWith(CultureInfo.InvariantCulture, _chars[_charPos]));

        _charPos++;

        ClearRecentString();

        SetToken(JsonToken.StartConstructor, constructorName);
      }
    }
开发者ID:DozenArts,项目名称:Newtonsoft.Json,代码行数:74,代码来源:JsonTextReader.cs

示例6: TryParseDateTimeOffset

        internal static bool TryParseDateTimeOffset(StringReference s, string dateFormatString, CultureInfo culture, out DateTimeOffset dt)
        {
            if (s.Length > 0)
            {
                int i = s.StartIndex;
                if (s[i] == '/')
                {
                    if (s.Length >= 9 && s.StartsWith("/Date(") && s.EndsWith(")/"))
                    {
                        if (TryParseDateTimeOffsetMicrosoft(s, out dt))
                        {
                            return true;
                        }
                    }
                }
                else if (s.Length >= 19 && s.Length <= 40 && char.IsDigit(s[i]) && s[i + 10] == 'T')
                {
                    if (TryParseDateTimeOffsetIso(s, out dt))
                    {
                        return true;
                    }
                }

                if (!string.IsNullOrEmpty(dateFormatString))
                {
                    if (TryParseDateTimeOffsetExact(s.ToString(), dateFormatString, culture, out dt))
                    {
                        return true;
                    }
                }
            }

            dt = default(DateTimeOffset);
            return false;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:35,代码来源:DateTimeUtils.cs

示例7: TryParseDateTimeMicrosoft

        private static bool TryParseDateTimeMicrosoft(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)
        {
            long ticks;
            TimeSpan offset;
            DateTimeKind kind;

            if (!TryParseMicrosoftDate(text, out ticks, out offset, out kind))
            {
                dt = default(DateTime);
                return false;
            }

            DateTime utcDateTime = ConvertJavaScriptTicksToDateTime(ticks);

            switch (kind)
            {
                case DateTimeKind.Unspecified:
                    dt = DateTime.SpecifyKind(utcDateTime.ToLocalTime(), DateTimeKind.Unspecified);
                    break;
                case DateTimeKind.Local:
                    dt = utcDateTime.ToLocalTime();
                    break;
                default:
                    dt = utcDateTime;
                    break;
            }

            dt = EnsureDateTime(dt, dateTimeZoneHandling);
            return true;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:30,代码来源:DateTimeUtils.cs

示例8: ReadOffsetMSDateTimeOffset

        public void ReadOffsetMSDateTimeOffset()
        {
            char[] c = @"12345/Date(1418924498000+0800)/12345".ToCharArray();
            StringReference reference = new StringReference(c, 5, c.Length - 10);

            DateTimeOffset d;
            DateTimeUtils.TryParseDateTimeOffset(reference, null, CultureInfo.InvariantCulture, out d);

            long initialTicks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(d.DateTime, d.Offset);

            Assert.AreEqual(1418924498000, initialTicks);
            Assert.AreEqual(8, d.Offset.Hours);
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:13,代码来源:DateTimeUtilsTests.cs

示例9: ParseNumber

    private void ParseNumber()
    {
      this.ShiftBufferIfNeeded();
      char c = this._chars[this._charPos];
      int startIndex = this._charPos;
      this.ReadNumberIntoBuffer();
      this._stringReference = new StringReference(this._chars, startIndex, this._charPos - startIndex);
      bool flag1 = char.IsDigit(c) && this._stringReference.Length == 1;
      bool flag2 = (int) c == 48 && this._stringReference.Length > 1 && ((int) this._stringReference.Chars[this._stringReference.StartIndex + 1] != 46 && (int) this._stringReference.Chars[this._stringReference.StartIndex + 1] != 101) && (int) this._stringReference.Chars[this._stringReference.StartIndex + 1] != 69;
      object obj;
      JsonToken newToken;
      if (this._readType == ReadType.ReadAsInt32)
      {
        if (flag1)
          obj = (object) ((int) c - 48);
        else if (flag2)
        {
          string str = this._stringReference.ToString();
          obj = (object) (str.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt32(str, 16) : Convert.ToInt32(str, 8));
        }
        else
          obj = (object) Convert.ToInt32(this._stringReference.ToString(), (IFormatProvider) CultureInfo.InvariantCulture);
        newToken = JsonToken.Integer;
      }
      else if (this._readType == ReadType.ReadAsDecimal)
      {
        if (flag1)
          obj = (object) ((Decimal) c - new Decimal(48));
        else if (flag2)
        {
          string str = this._stringReference.ToString();
          obj = (object) Convert.ToDecimal(str.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(str, 16) : Convert.ToInt64(str, 8));
        }
        else
          obj = (object) Decimal.Parse(this._stringReference.ToString(), NumberStyles.Number | NumberStyles.AllowExponent, (IFormatProvider) CultureInfo.InvariantCulture);
        newToken = JsonToken.Float;
      }
      else if (flag1)
      {
        obj = (object) ((long) c - 48L);
        newToken = JsonToken.Integer;
      }
      else if (flag2)
      {
        string str = this._stringReference.ToString();
        obj = (object) (str.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(str, 16) : Convert.ToInt64(str, 8));
        newToken = JsonToken.Integer;
      }
      else
      {
        string str = this._stringReference.ToString();
        if (str.IndexOf('.') == -1 && str.IndexOf('E') == -1)
        {
          if (str.IndexOf('e') == -1)
          {
            try
            {
              obj = (object) Convert.ToInt64(str, (IFormatProvider) CultureInfo.InvariantCulture);
            }
            catch (OverflowException ex)
            {
              throw JsonReaderException.Create((JsonReader) this, StringUtils.FormatWith("JSON integer {0} is too large or small for an Int64.", (IFormatProvider) CultureInfo.InvariantCulture, (object) str), (Exception) ex);
            }
            newToken = JsonToken.Integer;
            goto label_24;
          }
        }
        obj = (object) Convert.ToDouble(str, (IFormatProvider) CultureInfo.InvariantCulture);
        newToken = JsonToken.Float;
      }
label_24:
      this.ClearRecentString();
      this.SetToken(newToken, obj);
    }
开发者ID:tanis2000,项目名称:FEZ,代码行数:74,代码来源:JsonTextReader.cs

示例10: ParseNumber

    private void ParseNumber()
    {
      ShiftBufferIfNeeded();

      char firstChar = _chars[_charPos];
      int initialPosition = _charPos;

      ReadNumberIntoBuffer();

      _stringReference = new StringReference(_chars, initialPosition, _charPos - initialPosition);

      object numberValue;
      JsonToken numberType;

      bool singleDigit = (char.IsDigit(firstChar) && _stringReference.Length == 1);
      bool nonBase10 = (firstChar == '0' && _stringReference.Length > 1
        && _stringReference.Chars[_stringReference.StartIndex + 1] != '.'
        && _stringReference.Chars[_stringReference.StartIndex + 1] != 'e'
        && _stringReference.Chars[_stringReference.StartIndex + 1] != 'E');

      if (_readType == ReadType.ReadAsInt32)
      {
        if (singleDigit)
        {
          // digit char values start at 48
          numberValue = firstChar - 48;
        }
        else if (nonBase10)
        {
          string number = _stringReference.ToString();

          // decimal.Parse doesn't support parsing hexadecimal values
          int integer = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
                           ? Convert.ToInt32(number, 16)
                           : Convert.ToInt32(number, 8);

          numberValue = integer;
        }
        else
        {
          numberValue = ConvertUtils.Int32Parse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length);
        }

        numberType = JsonToken.Integer;
      }
      else if (_readType == ReadType.ReadAsDecimal)
      {
        if (singleDigit)
        {
          // digit char values start at 48
          numberValue = (decimal)firstChar - 48;
        }
        else if (nonBase10)
        {
          string number = _stringReference.ToString();

          // decimal.Parse doesn't support parsing hexadecimal values
          long integer = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
                           ? Convert.ToInt64(number, 16)
                           : Convert.ToInt64(number, 8);

          numberValue = Convert.ToDecimal(integer);
        }
        else
        {
          string number = _stringReference.ToString();

          numberValue = decimal.Parse(number, NumberStyles.Number | NumberStyles.AllowExponent, CultureInfo.InvariantCulture);
        }

        numberType = JsonToken.Float;
      }
      else
      {
        if (singleDigit)
        {
          // digit char values start at 48
          numberValue = (long)firstChar - 48;
          numberType = JsonToken.Integer;
        }
        else if (nonBase10)
        {
          string number = _stringReference.ToString();

          numberValue = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
                          ? Convert.ToInt64(number, 16)
                          : Convert.ToInt64(number, 8);
          numberType = JsonToken.Integer;
        }
        else
        {
          long value;
          ParseResult parseResult = ConvertUtils.Int64TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value);
          if (parseResult == ParseResult.Success)
          {
            numberValue = value;
            numberType = JsonToken.Integer;
          }
          else if (parseResult == ParseResult.Invalid)
          {
//.........这里部分代码省略.........
开发者ID:CragonGame,项目名称:GameCloud.IM,代码行数:101,代码来源:RT_JsonTextReader.cs

示例11: ReadDollarStringIntoBuffer

        private void ReadDollarStringIntoBuffer(char quote)
        { 
            //_charPos--; //wrong, because _charPos may be 0.

            var currentPos = _charPos;
            DlState _state = DlState.FirstDollar;

            string tag = null;
            int firstDollarIndex = currentPos;
            int thirdDollarIndex = currentPos;

            firstDollarIndex = currentPos - 1;

            while (true)
            {
                char c = _chars[currentPos];
                
                switch (c)
                {
                    case '\0':
                        if (_charsUsed == currentPos)
                        {
                            currentPos--;

                            if (ReadData(true) == 0)
                            {
                                _charPos = currentPos;
                                throw JsonReaderException.Create(this, "Unterminated string. Expected delimiter: {0}.".FormatWith(CultureInfo.InvariantCulture, quote));
                            }
                        }
                        break;
                    case '$':
                    case '`':
                        if (c != quote)
                        {
                            currentPos++;
                            continue;
                        }

                        switch (_state)
                        {
                            case DlState.None:
                                firstDollarIndex = currentPos;
                                _state = DlState.FirstDollar;
                                break;
                            case DlState.FirstDollar:
                                tag = new string(_chars, firstDollarIndex + 1, currentPos - firstDollarIndex - 1);
                                _state = DlState.InString;
                                break;
                            case DlState.InString:
                                thirdDollarIndex = currentPos;
                                _state = DlState.ThirdDollar;
                                break;
                            case DlState.ThirdDollar:
                                {
                                    bool match = false;
                                    if (currentPos - thirdDollarIndex - 1 == tag.Length)
                                    {
                                        var testTag = new string(_chars, thirdDollarIndex + 1, currentPos - thirdDollarIndex - 1);
                                        if (testTag == tag)
                                        {
                                            match = true;
                                        }
                                    }
                                    if (match)
                                    {
                                        var start = firstDollarIndex + tag.Length + 2;
                                        _stringReference = new StringReference(_chars, start, thirdDollarIndex - start);
                                        _state = DlState.Complete;
                                        currentPos++;
                                        _charPos = currentPos;
                                        return;
                                    }
                                    else
                                    {
                                        thirdDollarIndex = currentPos;
                                    }
                                }

                                break;
                            case DlState.Complete:
                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }//end switch

                currentPos++;
            }
        }
开发者ID:alanthinker,项目名称:Newtonsoft.Json,代码行数:93,代码来源:JsonTextReader.cs

示例12: ParseNumber

        private void ParseNumber(ReadType readType)
        {
            ShiftBufferIfNeeded();

            char firstChar = _chars[_charPos];
            int initialPosition = _charPos;

            ReadNumberIntoBuffer();

            // set state to PostValue now so that if there is an error parsing the number then the reader can continue
            SetPostValueState(true);

            _stringReference = new StringReference(_chars, initialPosition, _charPos - initialPosition);

            object numberValue;
            JsonToken numberType;

            bool singleDigit = (char.IsDigit(firstChar) && _stringReference.Length == 1);
            bool nonBase10 = (firstChar == '0' && _stringReference.Length > 1 && _stringReference.Chars[_stringReference.StartIndex + 1] != '.' && _stringReference.Chars[_stringReference.StartIndex + 1] != 'e' && _stringReference.Chars[_stringReference.StartIndex + 1] != 'E');

            if (readType == ReadType.ReadAsString)
            {
                string number = _stringReference.ToString();

                // validate that the string is a valid number
                if (nonBase10)
                {
                    try
                    {
                        if (number.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
                        {
                            Convert.ToInt64(number, 16);
                        }
                        else
                        {
                            Convert.ToInt64(number, 8);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ThrowReaderError("Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, number), ex);
                    }
                }
                else
                {
                    double value;
                    if (!double.TryParse(number, NumberStyles.Float, CultureInfo.InvariantCulture, out value))
                    {
                        throw ThrowReaderError("Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString()));
                    }
                }

                numberType = JsonToken.String;
                numberValue = number;
            }
            else if (readType == ReadType.ReadAsInt32)
            {
                if (singleDigit)
                {
                    // digit char values start at 48
                    numberValue = firstChar - 48;
                }
                else if (nonBase10)
                {
                    string number = _stringReference.ToString();

                    try
                    {
                        int integer = number.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt32(number, 16) : Convert.ToInt32(number, 8);

                        numberValue = integer;
                    }
                    catch (Exception ex)
                    {
                        throw ThrowReaderError("Input string '{0}' is not a valid integer.".FormatWith(CultureInfo.InvariantCulture, number), ex);
                    }
                }
                else
                {
                    int value;
                    ParseResult parseResult = ConvertUtils.Int32TryParse(_stringReference.Chars, _stringReference.StartIndex, _stringReference.Length, out value);
                    if (parseResult == ParseResult.Success)
                    {
                        numberValue = value;
                    }
                    else if (parseResult == ParseResult.Overflow)
                    {
                        throw ThrowReaderError("JSON integer {0} is too large or small for an Int32.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString()));
                    }
                    else
                    {
                        throw ThrowReaderError("Input string '{0}' is not a valid integer.".FormatWith(CultureInfo.InvariantCulture, _stringReference.ToString()));
                    }
                }

                numberType = JsonToken.Integer;
            }
            else if (readType == ReadType.ReadAsDecimal)
            {
                if (singleDigit)
//.........这里部分代码省略.........
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:101,代码来源:JsonTextReader.cs

示例13: ParseNumber

 // Token: 0x06000719 RID: 1817
 // RVA: 0x00039FE8 File Offset: 0x000381E8
 private void ParseNumber()
 {
     this.ShiftBufferIfNeeded();
     char c = this._chars[this._charPos];
     int charPos = this._charPos;
     this.ReadNumberIntoBuffer();
     base.SetPostValueState(true);
     this._stringReference = new StringReference(this._chars, charPos, this._charPos - charPos);
     bool flag = char.IsDigit(c) && this._stringReference.Length == 1;
     bool flag2 = c == '0' && this._stringReference.Length > 1 && this._stringReference.Chars[this._stringReference.StartIndex + 1] != '.' && this._stringReference.Chars[this._stringReference.StartIndex + 1] != 'e' && this._stringReference.Chars[this._stringReference.StartIndex + 1] != 'E';
     object value;
     JsonToken newToken;
     if (this._readType == ReadType.ReadAsInt32)
     {
         if (flag)
         {
             value = (int)(c - '0');
         }
         else
         {
             if (flag2)
             {
                 string text = this._stringReference.ToString();
                 try
                 {
                     int num = text.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt32(text, 16) : Convert.ToInt32(text, 8);
                     value = num;
                     goto IL_186;
                 }
                 catch (Exception ex)
                 {
                     throw JsonReaderException.Create(this, StringUtils.FormatWith("Input string '{0}' is not a valid integer.", CultureInfo.InvariantCulture, text), ex);
                 }
             }
             int num2;
             ParseResult parseResult = ConvertUtils.Int32TryParse(this._stringReference.Chars, this._stringReference.StartIndex, this._stringReference.Length, out num2);
             if (parseResult == ParseResult.Success)
             {
                 value = num2;
             }
             else
             {
                 if (parseResult == ParseResult.Overflow)
                 {
                     throw JsonReaderException.Create(this, StringUtils.FormatWith("JSON integer {0} is too large or small for an Int32.", CultureInfo.InvariantCulture, this._stringReference.ToString()));
                 }
                 throw JsonReaderException.Create(this, StringUtils.FormatWith("Input string '{0}' is not a valid integer.", CultureInfo.InvariantCulture, this._stringReference.ToString()));
             }
         }
         IL_186:
         newToken = JsonToken.Integer;
     }
     else if (this._readType == ReadType.ReadAsDecimal)
     {
         if (flag)
         {
             value = c - 48m;
         }
         else
         {
             if (flag2)
             {
                 string text2 = this._stringReference.ToString();
                 try
                 {
                     long value2 = text2.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(text2, 16) : Convert.ToInt64(text2, 8);
                     value = Convert.ToDecimal(value2);
                     goto IL_2A3;
                 }
                 catch (Exception ex2)
                 {
                     throw JsonReaderException.Create(this, StringUtils.FormatWith("Input string '{0}' is not a valid decimal.", CultureInfo.InvariantCulture, text2), ex2);
                 }
             }
             string s = this._stringReference.ToString();
             decimal num3;
             if (!decimal.TryParse(s, NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowLeadingSign | NumberStyles.AllowTrailingSign | NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands | NumberStyles.AllowExponent, CultureInfo.InvariantCulture, out num3))
             {
                 throw JsonReaderException.Create(this, StringUtils.FormatWith("Input string '{0}' is not a valid decimal.", CultureInfo.InvariantCulture, this._stringReference.ToString()));
             }
             value = num3;
         }
         IL_2A3:
         newToken = JsonToken.Float;
     }
     else if (flag)
     {
         value = (long)((ulong)c - 48uL);
         newToken = JsonToken.Integer;
     }
     else if (flag2)
     {
         string text3 = this._stringReference.ToString();
         try
         {
             value = (text3.StartsWith("0x", StringComparison.OrdinalIgnoreCase) ? Convert.ToInt64(text3, 16) : Convert.ToInt64(text3, 8));
         }
         catch (Exception ex3)
//.........这里部分代码省略.........
开发者ID:newchild,项目名称:Project-DayZero,代码行数:101,代码来源:JsonTextReader.cs

示例14: ParseConstructor

 // Token: 0x06000718 RID: 1816
 // RVA: 0x00039E54 File Offset: 0x00038054
 private void ParseConstructor()
 {
     if (!this.MatchValueWithTrailingSeparator("new"))
     {
         throw JsonReaderException.Create(this, "Unexpected content while parsing JSON.");
     }
     this.EatWhitespace(false);
     int charPos = this._charPos;
     char c;
     while (true)
     {
         c = this._chars[this._charPos];
         if (c == '\0')
         {
             if (this._charsUsed != this._charPos)
             {
                 goto IL_6F;
             }
             if (this.ReadData(true) == 0)
             {
                 break;
             }
         }
         else
         {
             if (!char.IsLetterOrDigit(c))
             {
                 goto IL_86;
             }
             this._charPos++;
         }
     }
     throw JsonReaderException.Create(this, "Unexpected end while parsing constructor.");
     IL_6F:
     int charPos2 = this._charPos;
     this._charPos++;
     goto IL_DA;
     IL_86:
     if (c == '\r')
     {
         charPos2 = this._charPos;
         this.ProcessCarriageReturn(true);
     }
     else if (c == '\n')
     {
         charPos2 = this._charPos;
         this.ProcessLineFeed();
     }
     else if (char.IsWhiteSpace(c))
     {
         charPos2 = this._charPos;
         this._charPos++;
     }
     else
     {
         if (c != '(')
         {
             throw JsonReaderException.Create(this, StringUtils.FormatWith("Unexpected character while parsing constructor: {0}.", CultureInfo.InvariantCulture, c));
         }
         charPos2 = this._charPos;
     }
     IL_DA:
     this._stringReference = new StringReference(this._chars, charPos, charPos2 - charPos);
     string value = this._stringReference.ToString();
     this.EatWhitespace(false);
     if (this._chars[this._charPos] != '(')
     {
         throw JsonReaderException.Create(this, StringUtils.FormatWith("Unexpected character while parsing constructor: {0}.", CultureInfo.InvariantCulture, this._chars[this._charPos]));
     }
     this._charPos++;
     this.ClearRecentString();
     base.SetToken(JsonToken.StartConstructor, value);
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:75,代码来源:JsonTextReader.cs

示例15: TryParseDateTimeIso

        internal static bool TryParseDateTimeIso(StringReference text, DateTimeZoneHandling dateTimeZoneHandling, out DateTime dt)
        {
            DateTimeParser dateTimeParser = new DateTimeParser();
            if (!dateTimeParser.Parse(text.Chars, text.StartIndex, text.Length))
            {
                dt = default(DateTime);
                return false;
            }

            DateTime d = CreateDateTime(dateTimeParser);

            long ticks;

            switch (dateTimeParser.Zone)
            {
                case ParserTimeZone.Utc:
                    d = new DateTime(d.Ticks, DateTimeKind.Utc);
                    break;

                case ParserTimeZone.LocalWestOfUtc:
                {
                    TimeSpan offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
                    ticks = d.Ticks + offset.Ticks;
                    if (ticks <= DateTime.MaxValue.Ticks)
                    {
                        d = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
                    }
                    else
                    {
                        ticks += d.GetUtcOffset().Ticks;
                        if (ticks > DateTime.MaxValue.Ticks)
                        {
                            ticks = DateTime.MaxValue.Ticks;
                        }

                        d = new DateTime(ticks, DateTimeKind.Local);
                    }
                    break;
                }
                case ParserTimeZone.LocalEastOfUtc:
                {
                    TimeSpan offset = new TimeSpan(dateTimeParser.ZoneHour, dateTimeParser.ZoneMinute, 0);
                    ticks = d.Ticks - offset.Ticks;
                    if (ticks >= DateTime.MinValue.Ticks)
                    {
                        d = new DateTime(ticks, DateTimeKind.Utc).ToLocalTime();
                    }
                    else
                    {
                        ticks += d.GetUtcOffset().Ticks;
                        if (ticks < DateTime.MinValue.Ticks)
                        {
                            ticks = DateTime.MinValue.Ticks;
                        }

                        d = new DateTime(ticks, DateTimeKind.Local);
                    }
                    break;
                }
            }

            dt = EnsureDateTime(d, dateTimeZoneHandling);
            return true;
        }
开发者ID:fszlin,项目名称:Newtonsoft.Json,代码行数:64,代码来源:DateTimeUtils.cs


注:本文中的Newtonsoft.Json.Utilities.StringReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。