本文整理汇总了C#中BsonDocument.ContainsValue方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.ContainsValue方法的具体用法?C# BsonDocument.ContainsValue怎么用?C# BsonDocument.ContainsValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.ContainsValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BsonDocMethod
static async Task BsonDocMethod()
{
var doc = new BsonDocument
{
{"name", "Sanya" }
};
doc.Add("age", 30);
doc["profession"] = "hacker";
var nestedArray = new BsonArray();
nestedArray.Add(new BsonDocument("color", "red"));
doc.Add("array", nestedArray);
Console.WriteLine(1);
//Console.WriteLine(doc.TryGetElement("name", out name));
Console.WriteLine(doc.Count());
Console.WriteLine();
Console.WriteLine(doc.ContainsValue("Sanya"));
Console.WriteLine(doc.Contains("name"));
Console.WriteLine(doc);
//var doc2 = new BsonDocument
//{
// { "Name", "Smith"},
// {"Something", "something else" },
// {"profession", "hacker" }
//};
//await collectionUsed.InsertManyAsync(new[] { doc, doc2 });
}
示例2: TestCreateFromDictionary
public void TestCreateFromDictionary()
{
var dictionary = new Dictionary<string, object> { { "x", 1 }, { "n", null }, { "a", new object[] { 1, null } } }; // null will be mapped to BsonNull.Value
var document = new BsonDocument(dictionary);
Assert.AreEqual(3, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreSame(BsonNull.Value, document["n"]);
Assert.IsTrue(document["a"].IsBsonArray);
Assert.AreEqual(2, document["a"].AsBsonArray.Count);
Assert.AreEqual(1, document["a"][0].AsInt32);
Assert.AreSame(BsonNull.Value, document["a"][1]);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.Contains("n"));
Assert.AreEqual(true, document.Contains("a"));
Assert.AreEqual(true, document.ContainsValue(1));
Assert.AreEqual(true, document.ContainsValue(BsonNull.Value));
}
示例3: TestContainsValue
public void TestContainsValue()
{
var document = new BsonDocument();
Assert.IsFalse(document.ContainsValue(1));
document["x"] = 1;
Assert.IsTrue(document.ContainsValue(1));
}
示例4: TestConstructorNoArgs
public void TestConstructorNoArgs()
{
var document = new BsonDocument();
Assert.AreEqual(false, document.AllowDuplicateNames);
Assert.IsInstanceOf<BsonDocument>(document.AsBsonDocument);
Assert.AreEqual(BsonType.Document, document.BsonType);
Assert.AreEqual(false, document.Contains("name"));
Assert.AreEqual(false, document.ContainsValue(0));
Assert.AreEqual(0, document.ElementCount);
Assert.AreEqual(0, document.Elements.Count());
Assert.AreEqual(false, document.IsBsonArray);
Assert.AreEqual(true, document.IsBsonDocument);
Assert.AreEqual(0, document.Names.Count());
#pragma warning disable 618
Assert.AreEqual(null, document.RawValue);
Assert.AreEqual(0, document.RawValues.Count());
#pragma warning restore
Assert.AreEqual(true, document.ToBoolean());
Assert.AreSame(document, document.ToBsonDocument());
Assert.AreEqual("{ }", document.ToJson());
Assert.AreEqual(0, document.Values.Count());
}
示例5: TestConstructorNameValue
public void TestConstructorNameValue()
{
var document = new BsonDocument("x", 1);
Assert.AreEqual(1, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.ContainsValue(1));
}
示例6: TestConstructorIDictionaryWithKeys
public void TestConstructorIDictionaryWithKeys()
{
var hashtable = (IDictionary)new Hashtable { { "x", 1 }, { "y", 2 } };
var keys = new string[] { "x" };
#pragma warning disable 618
var document = new BsonDocument(hashtable, keys);
#pragma warning restore
Assert.AreEqual(1, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.ContainsValue(1));
}
示例7: TestConstructorIDictionaryGenericWithKeys
public void TestConstructorIDictionaryGenericWithKeys()
{
var dictionary = (IDictionary<string, object>)new Dictionary<string, object> { { "x", 1 }, { "y", 2 } };
var keys = new string[] { "x" };
#pragma warning disable 618
var document = new BsonDocument(dictionary, keys);
#pragma warning restore
Assert.AreEqual(1, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.ContainsValue(1));
}
示例8: TestConstructorIDictionaryGeneric
public void TestConstructorIDictionaryGeneric()
{
var dictionary = (IDictionary<string, object>)new Dictionary<string, object> { { "x", 1 } };
var document = new BsonDocument(dictionary);
Assert.AreEqual(1, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.ContainsValue(1));
}
示例9: TestConstructorIDictionary
public void TestConstructorIDictionary()
{
var hashtable = (IDictionary)new Hashtable { { "x", 1 } };
var document = new BsonDocument(hashtable);
Assert.AreEqual(1, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.ContainsValue(1));
}
示例10: TestConstructorElementsParams
public void TestConstructorElementsParams()
{
var element1 = new BsonElement("x", 1);
var element2 = new BsonElement("y", 2);
#pragma warning disable 618
var document = new BsonDocument(element1, element2);
#pragma warning restore
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(2, document["y"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.Contains("y"));
Assert.AreEqual(true, document.ContainsValue(1));
Assert.AreEqual(true, document.ContainsValue(2));
Assert.AreSame(element1, document.GetElement("x"));
Assert.AreSame(element2, document.GetElement("y"));
}
示例11: TestConstructorElementsDocument
public void TestConstructorElementsDocument()
{
var originalDocument = new BsonDocument { { "x", 1 }, { "y", 2 } };
var document = new BsonDocument(originalDocument);
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(2, document["y"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.Contains("y"));
Assert.AreEqual(true, document.ContainsValue(1));
Assert.AreEqual(true, document.ContainsValue(2));
Assert.AreSame(originalDocument.GetElement("x"), document.GetElement("x"));
Assert.AreSame(originalDocument.GetElement("y"), document.GetElement("y"));
}
示例12: TestConstructorElements
public void TestConstructorElements()
{
var elements = new BsonElement[] {
new BsonElement("x", 1),
new BsonElement("y", 2)
};
var document = new BsonDocument((IEnumerable<BsonElement>)elements);
Assert.AreEqual(2, document.ElementCount);
Assert.AreEqual(1, document["x"].AsInt32);
Assert.AreEqual(2, document["y"].AsInt32);
Assert.AreEqual(true, document.Contains("x"));
Assert.AreEqual(true, document.Contains("y"));
Assert.AreEqual(true, document.ContainsValue(1));
Assert.AreEqual(true, document.ContainsValue(2));
Assert.AreSame(elements[0], document.GetElement("x"));
Assert.AreSame(elements[1], document.GetElement("y"));
}
示例13: TestConstructorElement
public void TestConstructorElement()
{
var element = new BsonElement("x", 1);
var document = new BsonDocument(element);
Assert.Equal(1, document.ElementCount);
Assert.Equal(1, document["x"].AsInt32);
Assert.Equal(true, document.Contains("x"));
Assert.Equal(true, document.ContainsValue(1));
Assert.Same(element.Value, document.GetElement("x").Value);
}