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


C# IO.JsonBuffer类代码示例

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


JsonBuffer类属于MongoDB.Bson.IO命名空间,在下文中一共展示了JsonBuffer类的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: 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


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