本文整理匯總了C#中BSONDocument.SetNumber方法的典型用法代碼示例。如果您正苦於以下問題:C# BSONDocument.SetNumber方法的具體用法?C# BSONDocument.SetNumber怎麽用?C# BSONDocument.SetNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BSONDocument
的用法示例。
在下文中一共展示了BSONDocument.SetNumber方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: TestSerialize1
public void TestSerialize1()
{
byte[] bdata;
BSONDocument doc = new BSONDocument();
doc.SetNumber("0", 1);
//0C-00-00-00 len
//10 type
//30-00 key
//01-00-00-00 int val
//00 zero term
bdata = doc.ToByteArray();
Assert.AreEqual("0C-00-00-00-10-30-00-01-00-00-00-00", doc.ToDebugDataString());
Assert.AreEqual(bdata.Length, (int) Convert.ToByte(doc.ToDebugDataString().Substring(0, 2), 16));
BSONDocument doc2 = new BSONDocument(doc.ToByteArray());
Assert.AreEqual(1, doc2.KeysCount);
int c = 0;
foreach (BSONValue bv in doc2) {
c++;
Assert.IsNotNull(bv);
Assert.AreEqual(BSONType.INT, bv.BSONType);
Assert.AreEqual("0", bv.Key);
Assert.AreEqual(1, bv.Value);
}
Assert.That(c > 0);
doc2.SetNumber("0", 2);
Assert.AreEqual(1, doc2.KeysCount);
object ival = doc2["0"];
Assert.IsInstanceOf(typeof(int), ival);
Assert.AreEqual(2, ival);
doc2.SetNumber("1", Int32.MaxValue);
//13-00-00-00
//10
//30-00
//02-00-00-00
//10-31-00
//FF-FF-FF-7F
//00
Assert.AreEqual("13-00-00-00-10-30-00-02-00-00-00-10-31-00-FF-FF-FF-7F-00",
doc2.ToDebugDataString());
doc2 = new BSONDocument(doc2);
Assert.AreEqual("13-00-00-00-10-30-00-02-00-00-00-10-31-00-FF-FF-FF-7F-00",
doc2.ToDebugDataString());
doc2 = new BSONDocument(doc2.ToByteArray());
Assert.AreEqual("13-00-00-00-10-30-00-02-00-00-00-10-31-00-FF-FF-FF-7F-00",
doc2.ToDebugDataString());
doc = new BSONDocument();
doc["a"] = 1;
Assert.AreEqual("0C-00-00-00-10-61-00-01-00-00-00-00", doc.ToDebugDataString());
}