當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。