本文整理汇总了C#中BsonValue类的典型用法代码示例。如果您正苦于以下问题:C# BsonValue类的具体用法?C# BsonValue怎么用?C# BsonValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonValue类属于命名空间,在下文中一共展示了BsonValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IndexKeysDocument
public IndexKeysDocument(
string name,
BsonValue value
)
: base(name, value)
{
}
示例2: Write
public static void Write(this BsonDocument document, string field, BsonValue value)
{
if (value == null) return;
if (field.StartsWith("_")) field = "PREFIX" + field;
// todo: make sure the search query builder also picks up this name change.
bool forcearray = (value.BsonType == BsonType.Document);
// anders kan er op zo'n document geen $elemMatch gedaan worden.
BsonElement element;
if (document.TryGetElement(field, out element))
{
if (element.Value.BsonType == BsonType.Array)
{
element.Value.AsBsonArray.Add(value);
}
else
{
document.Remove(field);
document.Append(field, new BsonArray() { element.Value, value ?? BsonNull.Value });
}
}
else
{
if (forcearray)
document.Append(field, new BsonArray() { value ?? BsonNull.Value });
else
document.Append(field, value);
}
}
示例3: RemoveMatchingElements
private void RemoveMatchingElements(BsonValue value, Regex regex)
{
if (value.BsonType == BsonType.Document)
{
var document = value.AsBsonDocument;
foreach (var name in document.Names.ToList())
{
if (regex.IsMatch(name))
{
document.Remove(name);
}
else
{
RemoveMatchingElements(document[name], regex);
}
}
}
else if (value.BsonType == BsonType.Array)
{
foreach (var item in value.AsBsonArray)
{
RemoveMatchingElements(item, regex);
}
}
}
示例4: SortByDocument
public SortByDocument(
string name,
BsonValue value
)
: base(name, value)
{
}
示例5: Serialize
/// <summary>
/// Json serialize a BsonValue into a TextWriter
/// </summary>
public static void Serialize(BsonValue value, TextWriter writer, bool pretty = false, bool writeBinary = true)
{
var w = new JsonWriter(writer);
w.Pretty = pretty;
w.WriteBinary = writeBinary;
w.Serialize(value ?? BsonValue.Null);
}
示例6: PreprocessHex
private BsonValue PreprocessHex(BsonValue value)
{
var array = value as BsonArray;
if (array != null)
{
for (var i = 0; i < array.Count; i++)
{
array[i] = PreprocessHex(array[i]);
}
return array;
}
var document = value as BsonDocument;
if (document != null)
{
if (document.ElementCount == 1 && document.GetElement(0).Name == "$hex" && document[0].IsString)
{
var hex = document[0].AsString;
var bytes = BsonUtils.ParseHexString(hex);
return new BsonBinaryData(bytes);
}
for (var i = 0; i < document.ElementCount; i++)
{
document[i] = PreprocessHex(document[i]);
}
return document;
}
return value;
}
示例7: BulkWriteOperationUpsert
// constructors
internal BulkWriteOperationUpsert(
int index,
BsonValue id)
{
_index = index;
_id = id;
}
示例8: BsonValueMemberProvider
public BsonValueMemberProvider(BsonValue value)
{
this.mValue = value;
this.mPropsToWrite = mValue.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => !IgnoredProperties.Contains(p.Name) && p.GetIndexParameters().Length == 0)
.ToArray();
}
示例9: CommandDocument
public CommandDocument(
string name,
BsonValue value
)
: base(name, value)
{
}
示例10: FormatMessage
private static string FormatMessage(BsonValue id, long n, string reason)
{
Ensure.IsNotNull(id, nameof(id));
Ensure.IsGreaterThanOrEqualToZero(n, nameof(n));
Ensure.IsNotNull(reason, nameof(reason));
return string.Format("GridFS chunk {0} of file id {1} is {2}.", n, id, reason);
}
示例11: ExpressionQuery
public static IMongoQuery ExpressionQuery(string name, Operator optor, BsonValue value)
{
switch (optor)
{
case Operator.EQ:
return M.Query.EQ(name, value);
case Operator.GT:
return M.Query.GT(name, value);
case Operator.GTE:
return M.Query.GTE(name, value);
case Operator.ISNULL:
return M.Query.EQ(name, null);
case Operator.LT:
return M.Query.LT(name, value);
case Operator.LTE:
return M.Query.LTE(name, value);
case Operator.NOTNULL:
return M.Query.NE(name, null);
default:
throw new ArgumentException(String.Format("Invalid operator {0} on token parameter {1}", optor.ToString(), name));
}
}
示例12: ConvertValue
private static object ConvertValue(string elementName, BsonValue value, IDictionary<string, string> aliases)
{
if (value.IsBsonDocument)
{
aliases = aliases.Where(x => x.Key.StartsWith(elementName + ".")).ToDictionary(x => x.Key.Remove(0, elementName.Length + 1), x => x.Value);
return value.AsBsonDocument.ToSimpleDictionary(aliases);
}
else if (value.IsBsonArray)
return value.AsBsonArray.Select(v => ConvertValue(elementName, v, aliases)).ToList();
else if (value.IsBoolean)
return value.AsBoolean;
else if (value.IsDateTime)
return value.AsDateTime;
else if (value.IsDouble)
return value.AsDouble;
else if (value.IsGuid)
return value.AsGuid;
else if (value.IsInt32)
return value.AsInt32;
else if (value.IsInt64)
return value.AsInt64;
else if (value.IsObjectId)
return value.AsObjectId;
else if (value.IsString)
return value.AsString;
else if (value.BsonType == BsonType.Binary)
return value.AsByteArray;
return value.RawValue;
}
示例13: TrySetArgument
protected override bool TrySetArgument(string name, BsonValue value)
{
switch (name)
{
case "filter":
_filter = (BsonDocument)value;
return true;
case "sort":
_options.Sort = value.ToBsonDocument();
return true;
case "limit":
_options.Limit = value.ToInt32();
return true;
case "skip":
_options.Skip = value.ToInt32();
return true;
case "batchSize":
_options.BatchSize = value.ToInt32();
return true;
case "modifiers":
_options.Modifiers = (BsonDocument)value;
return true;
}
return false;
}
示例14: _assertRequired
private static void _assertRequired(Property property, BsonValue value)
{
if (property.Options.Required && value == BsonNull.Value)
{
throw new ArgumentException("the property \"" + property.Name + "\" is required and connot be null");
}
}
示例15: QueryDocument
public QueryDocument(
string name,
BsonValue value
)
: base(name, value)
{
}