本文整理汇总了C#中Newtonsoft.Json.Bson.BsonWriter.WriteStartArray方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteStartArray方法的具体用法?C# BsonWriter.WriteStartArray怎么用?C# BsonWriter.WriteStartArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Bson.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteStartArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteValues
public void WriteValues()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue(long.MaxValue);
writer.WriteValue((ulong)long.MaxValue);
writer.WriteValue(int.MaxValue);
writer.WriteValue((uint)int.MaxValue);
writer.WriteValue(byte.MaxValue);
writer.WriteValue(sbyte.MaxValue);
writer.WriteValue('a');
writer.WriteValue(decimal.MaxValue);
writer.WriteValue(double.MaxValue);
writer.WriteValue(float.MaxValue);
writer.WriteValue(true);
writer.WriteValue(new byte[] { 0, 1, 2, 3, 4 });
writer.WriteValue(new DateTimeOffset(2000, 12, 29, 12, 30, 0, TimeSpan.Zero));
writer.WriteValue(new DateTime(2000, 12, 29, 12, 30, 0, DateTimeKind.Utc));
writer.WriteEnd();
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual("8C-00-00-00-12-30-00-FF-FF-FF-FF-FF-FF-FF-7F-12-31-00-FF-FF-FF-FF-FF-FF-FF-7F-10-32-00-FF-FF-FF-7F-10-33-00-FF-FF-FF-7F-10-34-00-FF-00-00-00-10-35-00-7F-00-00-00-02-36-00-02-00-00-00-61-00-01-37-00-00-00-00-00-00-00-F0-45-01-38-00-FF-FF-FF-FF-FF-FF-EF-7F-01-39-00-00-00-00-E0-FF-FF-EF-47-08-31-30-00-01-05-31-31-00-05-00-00-00-02-00-01-02-03-04-09-31-32-00-40-C5-E2-BA-E3-00-00-00-09-31-33-00-40-C5-E2-BA-E3-00-00-00-00", bson);
}
示例2: WriteReadEmptyAndNullStrings
public void WriteReadEmptyAndNullStrings()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue("Content!");
writer.WriteValue("");
writer.WriteValue((string)null);
writer.WriteEndArray();
ms.Seek(0, SeekOrigin.Begin);
BsonReader reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("Content!", reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.String, reader.TokenType);
Assert.AreEqual("", reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Null, reader.TokenType);
Assert.AreEqual(null, reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
}
示例3: WriteRawValue
public void WriteRawValue()
{
ExceptionAssert.Throws<JsonWriterException>(() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteRawValue("fail");
}, "Cannot write raw JSON as BSON. Path ''.");
}
示例4: WriteConstructor
public void WriteConstructor()
{
ExceptionAssert.Throws<JsonWriterException>(() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteStartConstructor("fail");
}, "Cannot write JSON constructor as BSON. Path ''.");
}
示例5: WriteNestedArray
public void WriteNestedArray()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartObject();
writer.WritePropertyName("_id");
writer.WriteValue(HexToBytes("4A-78-93-79-17-22-00-00-00-00-61-CF"));
writer.WritePropertyName("a");
writer.WriteStartArray();
for (int i = 1; i <= 8; i++)
{
double value = (i != 5)
? Convert.ToDouble(i)
: 5.78960446186581E+77d;
writer.WriteValue(value);
}
writer.WriteEndArray();
writer.WritePropertyName("b");
writer.WriteValue("test");
writer.WriteEndObject();
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
string expected = "87-00-00-00-05-5F-69-64-00-0C-00-00-00-00-4A-78-93-79-17-22-00-00-00-00-61-CF-04-61-00-5D-00-00-00-01-30-00-00-00-00-00-00-00-F0-3F-01-31-00-00-00-00-00-00-00-00-40-01-32-00-00-00-00-00-00-00-08-40-01-33-00-00-00-00-00-00-00-10-40-01-34-00-00-00-00-00-00-00-14-50-01-35-00-00-00-00-00-00-00-18-40-01-36-00-00-00-00-00-00-00-1C-40-01-37-00-00-00-00-00-00-00-20-40-00-02-62-00-05-00-00-00-74-65-73-74-00-00";
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
}
示例6: WriteBytes
public void WriteBytes()
{
byte[] data = Encoding.UTF8.GetBytes("Hello world!");
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue("a");
writer.WriteValue("b");
writer.WriteValue(data);
writer.WriteEndArray();
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-00-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00";
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
BsonReader reader = new BsonReader(new MemoryStream(ms.ToArray()));
reader.ReadRootValueAsArray = true;
reader.Read();
reader.Read();
reader.Read();
reader.Read();
Assert.AreEqual(JsonToken.Bytes, reader.TokenType);
CollectionAssert.AreEquivalent(data, (byte[])reader.Value);
}
示例7: WriteArrayBsonFromSite
public void WriteArrayBsonFromSite()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue("a");
writer.WriteValue("b");
writer.WriteValue("c");
writer.WriteEndArray();
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
string expected = "20-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-02-32-00-02-00-00-00-63-00-00";
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
}
示例8: WriteBytes
public void WriteBytes()
{
byte[] data = Encoding.UTF8.GetBytes("Hello world!");
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue("a");
writer.WriteValue("b");
writer.WriteValue(data);
writer.WriteEndArray();
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
string expected = "2B-00-00-00-02-30-00-02-00-00-00-61-00-02-31-00-02-00-00-00-62-00-05-32-00-0C-00-00-00-02-48-65-6C-6C-6F-20-77-6F-72-6C-64-21-00";
string bson = MiscellaneousUtils.BytesToHex(ms.ToArray());
Assert.AreEqual(expected, bson);
}
示例9: WriteDouble
public void WriteDouble()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteValue(99.99d);
writer.WriteEnd();
string bson = BytesToHex(ms.ToArray());
Assert.AreEqual("10-00-00-00-01-30-00-8F-C2-F5-28-5C-FF-58-40-00", bson);
}
示例10: WriteComment
public void WriteComment()
{
ExceptionAssert.Throws<JsonWriterException>("Cannot write JSON comment as BSON. Path ''.",
() =>
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteComment("fail");
});
}
示例11: WriteAndReadEmptyListsAndDictionaries
public void WriteAndReadEmptyListsAndDictionaries()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartObject();
writer.WritePropertyName("Arguments");
writer.WriteStartObject();
writer.WriteEndObject();
writer.WritePropertyName("List");
writer.WriteStartArray();
writer.WriteEndArray();
writer.WriteEndObject();
string bson = BitConverter.ToString(ms.ToArray());
Assert.AreEqual("20-00-00-00-03-41-72-67-75-6D-65-6E-74-73-00-05-00-00-00-00-04-4C-69-73-74-00-05-00-00-00-00-00", bson);
BsonReader reader = new BsonReader(new MemoryStream(MiscellaneousUtils.HexToBytes(bson)));
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.AreEqual("Arguments", reader.Value.ToString());
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartObject, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.PropertyName, reader.TokenType);
Assert.AreEqual("List", reader.Value.ToString());
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndObject, reader.TokenType);
Assert.IsFalse(reader.Read());
}
示例12: WriteRawValue
public void WriteRawValue()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteRawValue("fail");
}
示例13: WriteConstructor
public void WriteConstructor()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteStartConstructor("fail");
}
示例14: WriteComment
public void WriteComment()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.WriteStartArray();
writer.WriteComment("fail");
}
示例15: WriteDateTimes
public void WriteDateTimes()
{
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
writer.DateTimeKindHandling = DateTimeKind.Unspecified;
writer.WriteStartArray();
writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc));
writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Local));
writer.WriteValue(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Unspecified));
writer.WriteEndArray();
ms.Seek(0, SeekOrigin.Begin);
BsonReader reader = new BsonReader(ms);
reader.ReadRootValueAsArray = true;
reader.DateTimeKindHandling = DateTimeKind.Utc;
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.StartArray, reader.TokenType);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Date, reader.TokenType);
Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Date, reader.TokenType);
Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.Date, reader.TokenType);
Assert.AreEqual(new DateTime(2000, 10, 12, 20, 55, 0, DateTimeKind.Utc), reader.Value);
Assert.IsTrue(reader.Read());
Assert.AreEqual(JsonToken.EndArray, reader.TokenType);
Assert.IsFalse(reader.Read());
}