本文整理汇总了C#中BsonDocument.ResolvePath方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.ResolvePath方法的具体用法?C# BsonDocument.ResolvePath怎么用?C# BsonDocument.ResolvePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.ResolvePath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Unset
UpdateCompiler Unset(BsonDocument document, string name)
{
var r = document.ResolvePath(name);
if (r != null)
{
if (r.Document != null)
r.Document.Remove(r.Key);
else
r.Array[r.Index] = BsonNull.Value;
}
return this;
}
示例2: Rename
UpdateCompiler Rename(BsonDocument document, string name, string newName)
{
var r1 = document.ResolvePath(name, true); //_131028_234439 Weird, we can rename in arrays but follow Mongo that cannot.
if (r1 != null)
{
BsonValue value;
if (r1.Document.TryGetValue(r1.Key, out value))
{
var r2 = document.EnsurePath(newName);
r1.Document.Remove(r1.Key);
r2.Document[r2.Key] = value;
}
}
return this;
}
示例3: Pull
static void Pull(BsonDocument document, string name, BsonValue value, bool all)
{
var r = document.ResolvePath(name);
if (r == null)
return;
BsonValue vArray;
if (r.Array != null)
vArray = r.Array[r.Index];
else if (!r.Document.TryGetValue(r.Key, out vArray))
return;
if (vArray.BsonType != BsonType.Array)
throw new InvalidOperationException(string.Format(null, @"Value ""{0}"" must be array.", name));
var array = vArray.AsBsonArray;
if (!all && value.BsonType == BsonType.Document)
{
//_131130_103226 Created in Update.Pull(query)
var wrapper = value as BsonDocumentWrapper;
if (wrapper != null)
value = (BsonValue)wrapper.WrappedObject;
var predicate = QueryCompiler.GetFunction(value.AsBsonDocument);
for (int i = array.Count; --i >= 0; )
{
var v = array[i];
if (v.BsonType == BsonType.Document && predicate(v.AsBsonDocument))
array.RemoveAt(i);
}
}
else
{
BsonArray values = all ? value.AsBsonArray : null;
for (int i = array.Count; --i >= 0; )
{
if (values == null)
{
if (value.CompareTo(array[i]) == 0)
array.RemoveAt(i);
}
else
{
if (values.ContainsByCompareTo(array[i]))
array.RemoveAt(i);
}
}
}
}
示例4: Pop
UpdateCompiler Pop(BsonDocument document, string name, int value)
{
var r = document.ResolvePath(name);
if (r == null)
return this;
BsonValue vArray;
if (r.Array != null)
{
vArray = r.Array[r.Index];
}
else if (!r.Document.TryGetValue(r.Key, out vArray))
{
return this;
}
if (vArray.BsonType != BsonType.Array)
throw new InvalidOperationException(string.Format(null, @"Value ""{0}"" must be array.", name));
var array = vArray.AsBsonArray;
if (array.Count > 0)
{
if (value < 0)
array.RemoveAt(0);
else
array.RemoveAt(array.Count - 1);
}
return this;
}
示例5: Bitwise
static void Bitwise(BsonDocument document, string name, BsonValue value, bool and)
{
var r = document.ResolvePath(name);
if (r == null)
return;
BsonValue old;
if (r.Array != null)
{
old = r.Array[r.Index];
if (old.BsonType != BsonType.Int32 && old.BsonType != BsonType.Int64)
throw new MongoException(string.Format(null, @"Item ""{0}"" must be Int32 or Int64.", name));
r.Array[r.Index] = and ? MyValue.BitwiseAnd(old, value) : MyValue.BitwiseOr(old, value);
}
else if (r.Document.TryGetValue(r.Key, out old))
{
if (old.BsonType != BsonType.Int32 && old.BsonType != BsonType.Int64)
throw new MongoException(string.Format(null, @"Field ""{0}"" must be Int32 or Int64.", name));
r.Document[r.Key] = and ? MyValue.BitwiseAnd(old, value) : MyValue.BitwiseOr(old, value);
}
}