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


C# JsonBuffer.Read方法代码示例

本文整理汇总了C#中MongoDB.Bson.IO.JsonBuffer.Read方法的典型用法代码示例。如果您正苦于以下问题:C# JsonBuffer.Read方法的具体用法?C# JsonBuffer.Read怎么用?C# JsonBuffer.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Bson.IO.JsonBuffer的用法示例。


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

示例1: GetNextToken

        /// <summary>
        /// Gets the next JsonToken from a JsonBuffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <returns>The next token.</returns>
        public static JsonToken GetNextToken(
            JsonBuffer buffer
        ) {
            // skip leading whitespace
            var c = buffer.Read();
            while (c != -1 && char.IsWhiteSpace((char) c)) {
                c = buffer.Read();
            }
            if (c == -1) {
                return new JsonToken(JsonTokenType.EndOfFile, "<eof>");
            }

            // leading character determines token type
            switch (c) {
                case '{': return new JsonToken(JsonTokenType.BeginObject, "{");
                case '}': return new JsonToken(JsonTokenType.EndObject, "}");
                case '[': return new JsonToken(JsonTokenType.BeginArray, "[");
                case ']': return new JsonToken(JsonTokenType.EndArray, "]");
                case ':': return new JsonToken(JsonTokenType.Colon, ":");
                case ',': return new JsonToken(JsonTokenType.Comma, ",");
                case '"': return GetStringToken(buffer);
                case '/': return GetRegularExpressionToken(buffer);
                default:
                    if (c == '-' || char.IsDigit((char) c)) {
                        return GetNumberToken(buffer, c);
                    } else if (c == '$' || char.IsLetter((char) c)) {
                        return GetUnquotedStringToken(buffer);
                    } else {
                        buffer.UnRead(c);
                        throw new FileFormatException(FormatMessage("Invalid JSON input", buffer, buffer.Position));
                    }
            }
        }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:38,代码来源:JsonScanner.cs

示例2: TestBeginObject

 public void TestBeginObject() {
     var json = "\t {x";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.BeginObject, token.Type);
     Assert.AreEqual("{", token.Lexeme);
     Assert.AreEqual('x', buffer.Read());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:8,代码来源:JsonScannerTests.cs

示例3: TestNameSeparator

 public void TestNameSeparator() {
     var json = "\t :x";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.Colon, token.Type);
     Assert.AreEqual(":", token.Lexeme);
     Assert.AreEqual('x', buffer.Read());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:8,代码来源:JsonScannerTests.cs

示例4: TestEndArray

 public void TestEndArray() {
     var json = "\t ]x";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.EndArray, token.Type);
     Assert.AreEqual("]", token.Lexeme);
     Assert.AreEqual('x', buffer.Read());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:8,代码来源:JsonScannerTests.cs

示例5: TestEndOfFile

 public void TestEndOfFile() {
     var json = "\t ";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.EndOfFile, token.Type);
     Assert.AreEqual("<eof>", token.Lexeme);
     Assert.AreEqual(-1, buffer.Read());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:8,代码来源:JsonScannerTests.cs

示例6: Test3CharacterString

 public void Test3CharacterString()
 {
     var json = "\t \"123\"x";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.String, token.Type);
     Assert.AreEqual("123", token.StringValue);
     Assert.AreEqual('x', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例7: TestTrue

 public void TestTrue()
 {
     var json = "\t true,";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.UnquotedString, token.Type);
     Assert.AreEqual("true", token.StringValue);
     Assert.AreEqual(',', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例8: TestTwelve

 public void TestTwelve()
 {
     var json = "\t 12,";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.Int32, token.Type);
     Assert.AreEqual("12", token.Lexeme);
     Assert.AreEqual(',', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例9: TestRegularExpressionEmpty

 public void TestRegularExpressionEmpty()
 {
     var json = "\t //,";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.RegularExpression, token.Type);
     Assert.AreEqual("//", token.Lexeme);
     Assert.AreEqual(',', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例10: TestRegularExpressionPatternAndOptions

 public void TestRegularExpressionPatternAndOptions()
 {
     var json = "\t /pattern/gim,";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.RegularExpression, token.Type);
     Assert.AreEqual("/pattern/gim", token.Lexeme);
     Assert.AreEqual(',', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例11: GetTenGenInt64

 private static JsonToken GetTenGenInt64(
     JsonBuffer buffer,
     int start
 ) {
     var firstDigit = buffer.Position;
     while (true) {
         var c = buffer.Read();
         if (c == ')') {
             var lexeme = buffer.Substring(start, buffer.Position - start);
             var digits = buffer.Substring(firstDigit, buffer.Position - firstDigit - 1);
             var value = XmlConvert.ToInt64(digits);
             return new Int64JsonToken(lexeme, value);
         }
         if (c == -1 || !char.IsDigit((char) c)) {
             throw new FileFormatException(FormatMessage("Invalid JSON NumberLong value", buffer, start));
         }
     }
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:18,代码来源:JsonScanner.cs

示例12: TestOneExponentMinuesTwelve

 public void TestOneExponentMinuesTwelve()
 {
     var json = "\t 1e-12,";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.Double, token.Type);
     Assert.AreEqual("1e-12", token.Lexeme);
     Assert.AreEqual(',', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例13: GetNumberToken

        private static JsonToken GetNumberToken(
            JsonBuffer buffer,
            int c // first character
        ) {
            // leading digit or '-' has already been read
            var start = buffer.Position - 1;
            NumberState state;
            switch (c) {
                case '-': state = NumberState.SawLeadingMinus; break;
                case '0': state = NumberState.SawLeadingZero; break;
                default: state = NumberState.SawIntegerDigits; break;
            }
            var type = JsonTokenType.Int64; // assume integer until proved otherwise

            while (true) {
                c = buffer.Read();
                switch (state) {
                    case NumberState.SawLeadingMinus:
                        switch (c) {
                            case '0':
                                state = NumberState.SawLeadingZero; 
                                break;
                            case 'I':
                                state = NumberState.SawMinusI;
                                break;
                            default:
                                if (char.IsDigit((char) c)) {
                                    state = NumberState.SawIntegerDigits;
                                } else {
                                    state = NumberState.Invalid;
                                }
                                break;
                        }
                        break;
                    case NumberState.SawLeadingZero:
                        switch (c) {
                            case '.':
                                state = NumberState.SawDecimalPoint;
                                break;
                            case 'e':
                            case 'E':
                                state = NumberState.SawExponentLetter;
                                break;
                            case ',':
                            case '}':
                            case ']':
                            case ')':
                            case -1:
                                state = NumberState.Done;
                                break;
                            default:
                                if (char.IsWhiteSpace((char) c)) {
                                    state = NumberState.Done;
                                } else {
                                    state = NumberState.Invalid;
                                }
                                break;
                        }
                        break;
                    case NumberState.SawIntegerDigits:
                        switch (c) {
                            case '.':
                                state = NumberState.SawDecimalPoint;
                                break;
                            case 'e':
                            case 'E':
                                state = NumberState.SawExponentLetter;
                                break;
                            case ',':
                            case '}':
                            case ']':
                            case ')':
                            case -1:
                                state = NumberState.Done;
                                break;
                            default:
                                if (char.IsDigit((char) c)) {
                                    state = NumberState.SawIntegerDigits;
                                } else if (char.IsWhiteSpace((char) c)) {
                                    state = NumberState.Done;
                                } else {
                                    state = NumberState.Invalid;
                                }
                                break;
                        }
                        break;
                    case NumberState.SawDecimalPoint:
                        type = JsonTokenType.Double;
                        if (char.IsDigit((char) c)) {
                            state = NumberState.SawFractionDigits;
                        } else {
                            state = NumberState.Invalid;
                        }
                        break;
                    case NumberState.SawFractionDigits:
                        switch (c) {
                            case 'e':
                            case 'E':
                                state = NumberState.SawExponentLetter;
                                break;
//.........这里部分代码省略.........
开发者ID:emiaj,项目名称:mongo-csharp-driver,代码行数:101,代码来源:JsonScanner.cs

示例14: TestZeroPointZero

 public void TestZeroPointZero()
 {
     var json = "\t 0.0,";
     var buffer = new JsonBuffer(json);
     var token = JsonScanner.GetNextToken(buffer);
     Assert.AreEqual(JsonTokenType.Double, token.Type);
     Assert.AreEqual("0.0", token.Lexeme);
     Assert.AreEqual(',', buffer.Read());
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:9,代码来源:JsonScannerTests.cs

示例15: GetStringToken

 private static JsonToken GetStringToken(
     JsonBuffer buffer,
     char quoteCharacter // either single or double quote
 ) {
     // opening quote has already been read
     var start = buffer.Position - 1;
     var sb = new StringBuilder();
     while (true) {
         var c = buffer.Read();
         switch (c) {
             case '\\':
                 c = buffer.Read();
                 switch (c) {
                     case '\'': sb.Append('\''); break;
                     case '"': sb.Append('"'); break;
                     case '\\': sb.Append('\\'); break;
                     case '/': sb.Append('/'); break;
                     case 'b': sb.Append('\b'); break;
                     case 'f': sb.Append('\f'); break;
                     case 'n': sb.Append('\n'); break;
                     case 'r': sb.Append('\r'); break;
                     case 't': sb.Append('\t'); break;
                     case 'u':
                         var u1 = buffer.Read();
                         var u2 = buffer.Read();
                         var u3 = buffer.Read();
                         var u4 = buffer.Read();
                         if (u4 != -1) {
                             var hex = new string(new char[] { (char) u1, (char) u2, (char) u3, (char) u4 });
                             var n = Convert.ToInt32(hex, 16);
                             sb.Append((char) n);
                         }
                         break;
                     default:
                         if (c != -1) {
                             var message = string.Format("Invalid escape sequence in JSON string '\\{0}'.", (char) c);
                             throw new FileFormatException(message);
                         }
                         break;
                 }
                 break;
             default:
                 if (c == quoteCharacter) {
                     var lexeme = buffer.Substring(start, buffer.Position - start);
                     return new StringJsonToken(JsonTokenType.String, lexeme, sb.ToString());
                 }
                 if (c != -1) {
                     sb.Append((char) c);
                 }
                 break;
         }
         if (c == -1) {
             throw new FileFormatException(FormatMessage("End of file in JSON string.", buffer, start));
         }
     }
 }
开发者ID:emiaj,项目名称:mongo-csharp-driver,代码行数:56,代码来源:JsonScanner.cs


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