• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IO.JsonBuffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



JsonBuffer类属于MongoDB.Bson.IO命名空间,在下文中一共展示了JsonBuffer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: JsonReader

 public JsonReader(
     JsonBuffer buffer
 )
 {
     this.buffer = buffer;
     this.context = new JsonReaderContext(null, ContextType.TopLevel);
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:7,代码来源:JsonReader.cs


示例3: JsonReader

 // constructors
 /// <summary>
 /// Initializes a new instance of the JsonReader class.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="settings">The reader settings.</param>
 public JsonReader(JsonBuffer buffer, JsonReaderSettings settings)
     : base(settings)
 {
     _buffer = buffer;
     _jsonReaderSettings = settings; // already frozen by base class
     _context = new JsonReaderContext(null, ContextType.TopLevel);
 }
开发者ID:dngorecki,项目名称:mongo-csharp-driver,代码行数:13,代码来源:JsonReader.cs


示例4: JsonReader

 /// <summary>
 /// Initializes a new instance of the JsonReader class.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <param name="settings">The reader settings.</param>
 public JsonReader(
     JsonBuffer buffer,
     JsonReaderSettings settings
 ) {
     this.buffer = buffer;
     this.settings = settings.Freeze();
     this.context = new JsonReaderContext(null, ContextType.TopLevel);
 }
开发者ID:emiaj,项目名称:mongo-csharp-driver,代码行数:13,代码来源:JsonReader.cs


示例5: 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


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: FormatMessage

 private static string FormatMessage(
     string message,
     JsonBuffer buffer,
     int start
 ) {
     var length = 20;
     string snippet;
     if (buffer.Position + length >= buffer.Length) {
         snippet = buffer.Substring(start);
     } else {
         snippet = buffer.Substring(start, length) + "...";
     }
     return string.Format("{0} '{1}'.", message, snippet);
 }
开发者ID:emiaj,项目名称:mongo-csharp-driver,代码行数:14,代码来源:JsonScanner.cs


示例11: 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


示例12: TestUnquotedString

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


示例13: TestZeroExponentMinusOne

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


示例14: 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


示例15: 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


示例16: GetRegularExpressionToken

        private static JsonToken GetRegularExpressionToken(
            JsonBuffer buffer
        ) {
            // opening slash has already been read
            var start = buffer.Position - 1;
            var state = RegularExpressionState.InPattern;
            while (true) {
                var c = buffer.Read();
                switch (state) {
                    case RegularExpressionState.InPattern:
                        switch (c) {
                            case '/': state = RegularExpressionState.InOptions; break;
                            case '\\': state = RegularExpressionState.InEscapeSequence; break;
                            default: state = RegularExpressionState.InPattern; break;
                        }
                        break;
                    case RegularExpressionState.InEscapeSequence:
                        state = RegularExpressionState.InPattern;
                        break;
                    case RegularExpressionState.InOptions:
                        switch (c) {
                            case 'g':
                            case 'i':
                            case 'm':
                                state = RegularExpressionState.InOptions;
                                break;
                            case ',':
                            case '}':
                            case ']':
                            case ')':
                            case -1:
                                state = RegularExpressionState.Done;
                                break;
                            default:
                                if (char.IsWhiteSpace((char) c)) {
                                    state = RegularExpressionState.Done;
                                } else {
                                    state = RegularExpressionState.Invalid;
                                }
                                break;
                        }
                        break;
                }

                switch (state) {
                    case RegularExpressionState.Done:
                        buffer.UnRead(c);
                        var lexeme = buffer.Substring(start, buffer.Position - start);
                        var regex = BsonRegularExpression.Create(lexeme);
                        return new RegularExpressionJsonToken(lexeme, regex);
                    case RegularExpressionState.Invalid:
                        throw new FileFormatException(FormatMessage("Invalid JSON regular expression", buffer, start));
                }
            }
        }
开发者ID:emiaj,项目名称:mongo-csharp-driver,代码行数:55,代码来源:JsonScanner.cs


示例17: 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


示例18: TestMinusOnePointTwo

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


示例19: 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


示例20: GetTenGenObjectId

 private static JsonToken GetTenGenObjectId(
     JsonBuffer buffer,
     int start
 ) {
     var c = buffer.Read();
     if (c != '"') {
         throw new FileFormatException(FormatMessage("Invalid JSON ObjectId value", buffer, start));
     }
     var firstHexDigit = buffer.Position;
     c = buffer.Read();
     while (c != '"') {
         if (
             !char.IsDigit((char) c) &&
             !(c >= 'a' && c <= 'f') &&
             !(c >= 'A' && c <= 'F')
         ) {
             throw new FileFormatException(FormatMessage("Invalid JSON ObjectId value", buffer, start));
         }
         c = buffer.Read();
     }
     var count = buffer.Position - 1 - firstHexDigit;
     if (count != 24) {
         throw new FileFormatException(FormatMessage("Invalid JSON ObjectId value", buffer, start));
     }
     var hexDigits = buffer.Substring(firstHexDigit, count);
     var objectId = ObjectId.Parse(hexDigits);
     c = buffer.Read();
     if (c != ')') {
         throw new FileFormatException(FormatMessage("Invalid JSON ObjectId value", buffer, start));
     }
     var lexeme = buffer.Substring(start, buffer.Position - start);
     return new ObjectIdJsonToken(lexeme, objectId);
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:33,代码来源:JsonScanner.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IO.JsonReaderContext类代码示例发布时间:2022-05-26
下一篇:
C# IO.BsonWriter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap