本文整理汇总了C#中BsonDocument.ToHashtable方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.ToHashtable方法的具体用法?C# BsonDocument.ToHashtable怎么用?C# BsonDocument.ToHashtable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.ToHashtable方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestToHashtableOtherTypes
public void TestToHashtableOtherTypes()
{
var document = new BsonDocument
{
{ "JavaScript", new BsonJavaScript("x = 1") },
{ "JavaScriptWithScope", new BsonJavaScriptWithScope("x = y", new BsonDocument("y", 1)) },
{ "MaxKey", BsonMaxKey.Value },
{ "MinKey", BsonMinKey.Value },
{ "Null", BsonNull.Value },
{ "RegularExpression", new BsonRegularExpression("abc") },
{ "Symbol", BsonSymbolTable.Lookup("name") },
{ "Timestamp", new BsonTimestamp(123L) },
{ "Undefined", BsonUndefined.Value },
};
var hashtable = document.ToHashtable();
Assert.AreEqual(9, hashtable.Count);
Assert.IsInstanceOf<BsonJavaScript>(hashtable["JavaScript"]);
Assert.IsInstanceOf<BsonJavaScriptWithScope>(hashtable["JavaScriptWithScope"]);
Assert.AreSame(BsonMaxKey.Value, hashtable["MaxKey"]);
Assert.AreSame(BsonMinKey.Value, hashtable["MinKey"]);
Assert.IsNull(hashtable["Null"]);
Assert.IsInstanceOf<BsonRegularExpression>(hashtable["RegularExpression"]);
Assert.IsInstanceOf<BsonSymbol>(hashtable["Symbol"]);
Assert.IsInstanceOf<BsonTimestamp>(hashtable["Timestamp"]);
Assert.AreSame(BsonUndefined.Value, hashtable["Undefined"]);
}
示例2: TestToHashtableOneObjectId
public void TestToHashtableOneObjectId()
{
var objectId = ObjectId.GenerateNewId();
var hashtable = new BsonDocument("x", objectId);
var dictionary = hashtable.ToHashtable();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<ObjectId>(dictionary["x"]);
Assert.AreEqual(objectId, dictionary["x"]);
}
示例3: TestToHashtableOneString
public void TestToHashtableOneString()
{
var document = new BsonDocument("x", "abc");
var hashtable = document.ToHashtable();
Assert.AreEqual(1, hashtable.Count);
Assert.IsInstanceOf<string>(hashtable["x"]);
Assert.AreEqual("abc", hashtable["x"]);
}
示例4: TestToHashtableOneGuidStandard
public void TestToHashtableOneGuidStandard()
{
var guid = Guid.NewGuid();
var hashtable = new BsonDocument("x", new BsonBinaryData(guid, GuidRepresentation.Standard));
var dictionary = hashtable.ToHashtable();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<Guid>(dictionary["x"]);
Assert.AreEqual(guid, dictionary["x"]);
}
示例5: TestToHashtableOneInt64
public void TestToHashtableOneInt64()
{
var document = new BsonDocument("x", 1L);
var hashtable = document.ToHashtable();
Assert.AreEqual(1, hashtable.Count);
Assert.IsInstanceOf<long>(hashtable["x"]);
Assert.AreEqual(1L, hashtable["x"]);
}
示例6: TestToHashtableOneDateTime
public void TestToHashtableOneDateTime()
{
var utcNow = DateTime.UtcNow;
var utcNowTruncated = utcNow.AddTicks(-(utcNow.Ticks % 10000));
var hashtable = new BsonDocument("x", utcNow);
var dictionary = hashtable.ToHashtable();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<DateTime>(dictionary["x"]);
Assert.AreEqual(DateTimeKind.Utc, ((DateTime)dictionary["x"]).Kind);
Assert.AreEqual(utcNowTruncated, dictionary["x"]);
}
示例7: TestToHashtableOneDouble
public void TestToHashtableOneDouble()
{
var document = new BsonDocument("x", 1.0);
var hashtable = document.ToHashtable();
Assert.AreEqual(1, hashtable.Count);
Assert.IsInstanceOf<double>(hashtable["x"]);
Assert.AreEqual(1.0, hashtable["x"]);
}
示例8: TestToHashtableOneBinary
public void TestToHashtableOneBinary()
{
var document = new BsonDocument("x", new BsonBinaryData(new byte[] { 1, 2, 3 }, BsonBinarySubType.Binary));
var hashtable = document.ToHashtable();
Assert.AreEqual(1, hashtable.Count);
Assert.IsInstanceOf<byte[]>(hashtable["x"]);
Assert.IsTrue(new byte[] { 1, 2, 3 }.SequenceEqual((byte[])hashtable["x"]));
}
示例9: TestToHashtableOneBoolean
public void TestToHashtableOneBoolean()
{
var document = new BsonDocument("x", true);
var dictionary = document.ToHashtable();
Assert.AreEqual(1, dictionary.Count);
Assert.IsInstanceOf<bool>(dictionary["x"]);
Assert.AreEqual(true, dictionary["x"]);
}
示例10: TestToHashtableNestedDocument
public void TestToHashtableNestedDocument()
{
var document = new BsonDocument
{
{ "x", 1 },
{ "nested", new BsonDocument { { "a", 1 }, { "b", 2 } } }
};
var hashtable = document.ToHashtable();
Assert.AreEqual(2, hashtable.Count);
Assert.IsInstanceOf<int>(hashtable["x"]);
Assert.AreEqual(1, hashtable["x"]);
Assert.IsInstanceOf<Hashtable>(hashtable["nested"]);
var nested = (Hashtable)hashtable["nested"];
Assert.IsInstanceOf<int>(nested["a"]);
Assert.IsInstanceOf<int>(nested["b"]);
Assert.AreEqual(1, nested["a"]);
Assert.AreEqual(2, nested["b"]);
}
示例11: TestToHashtableNestedArray
public void TestToHashtableNestedArray()
{
var document = new BsonDocument
{
{ "x", 1 },
{ "array", new BsonArray { 1, "abc" } }
};
var hashtable = document.ToHashtable();
Assert.AreEqual(2, hashtable.Count);
Assert.IsInstanceOf<int>(hashtable["x"]);
Assert.AreEqual(1, hashtable["x"]);
Assert.IsInstanceOf<object[]>(hashtable["array"]);
var nested = (object[])hashtable["array"];
Assert.IsInstanceOf<int>(nested[0]);
Assert.IsInstanceOf<string>(nested[1]);
Assert.AreEqual(1, nested[0]);
Assert.AreEqual("abc", nested[1]);
}
示例12: TestToHashtableEmpty
public void TestToHashtableEmpty()
{
var document = new BsonDocument();
var hashtable = document.ToHashtable();
Assert.AreEqual(0, hashtable.Count);
}
示例13: TestToHashtableOneInt32
public void TestToHashtableOneInt32()
{
var document = new BsonDocument("x", 1);
var hashtable = document.ToHashtable();
Assert.Equal(1, hashtable.Count);
Assert.IsType<int>(hashtable["x"]);
Assert.Equal(1, hashtable["x"]);
}
示例14: TestToHashtableOneGuidLegacy
public void TestToHashtableOneGuidLegacy()
{
var guid = Guid.NewGuid();
var hashtable = new BsonDocument("x", new BsonBinaryData(guid, GuidRepresentation.CSharpLegacy));
var dictionary = hashtable.ToHashtable();
Assert.Equal(1, dictionary.Count);
Assert.IsType<Guid>(dictionary["x"]);
Assert.Equal(guid, dictionary["x"]);
}