本文整理汇总了C#中BsonWriter类的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter类的具体用法?C# BsonWriter怎么用?C# BsonWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonWriter类属于命名空间,在下文中一共展示了BsonWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (IsRelationalAssociation(bsonWriter, value))
RelationSerializer.Instance.Serialize(bsonWriter, nominalType, value, options);
else
CustomBsonClassMapSerializer.Instance.Serialize(bsonWriter, nominalType, value, options);
}
示例2: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
IDictionary<string, object> obj = value as IDictionary<string, object>;
if (obj == null)
{
bsonWriter.WriteNull();
return;
}
bsonWriter.WriteStartDocument();
foreach (var member in obj)
{
bsonWriter.WriteName(member.Key);
object memberValue = member.Value;
if (memberValue == null)
{
bsonWriter.WriteNull();
}
else
{
nominalType = memberValue.GetType();
var serializer = BsonSerializer.LookupSerializer(nominalType);
serializer.Serialize(bsonWriter, nominalType, memberValue, options);
}
}
bsonWriter.WriteEndDocument();
}
示例3: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options
)
{
if (value == null)
{
bsonWriter.WriteNull();
return;
}
var nvc = (NameValueCollection)value;
bsonWriter.WriteStartArray();
foreach (var key in nvc.AllKeys)
{
foreach (var val in nvc.GetValues(key))
{
bsonWriter.WriteStartArray();
StringSerializer.Instance.Serialize(bsonWriter, typeof(string), key, options);
StringSerializer.Instance.Serialize(bsonWriter, typeof(string), val, options);
bsonWriter.WriteEndArray();
}
}
bsonWriter.WriteEndArray();
}
示例4: IsRelationalAssociation
private static bool IsRelationalAssociation(BsonWriter bsonWriter, object value)
{
if (value == null || bsonWriter.State != BsonWriterState.Value)
return false;
return IsRelationalType(value.GetType());
}
示例5: WriteBson
private void WriteBson(BsonWriter writer, Regex regex)
{
// Regular expression - The first cstring is the regex pattern, the second
// is the regex options string. Options are identified by characters, which
// must be stored in alphabetical order. Valid options are 'i' for case
// insensitive matching, 'm' for multiline matching, 'x' for verbose mode,
// 'l' to make \w, \W, etc. locale dependent, 's' for dotall mode
// ('.' matches everything), and 'u' to make \w, \W, etc. match unicode.
string options = null;
if (HasFlag(regex.Options, RegexOptions.IgnoreCase))
options += "i";
if (HasFlag(regex.Options, RegexOptions.Multiline))
options += "m";
if (HasFlag(regex.Options, RegexOptions.Singleline))
options += "s";
options += "u";
if (HasFlag(regex.Options, RegexOptions.ExplicitCapture))
options += "x";
writer.WriteRegex(regex.ToString(), options);
}
示例6: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
var idPropertyInfo = value.GetType().GetProperty("ID");
var id = (ObjectId) idPropertyInfo.GetValue(value, null);
if (id == ObjectId.Empty)
throw new Exception("Relational associations must be saved before saving the parent relation");
ObjectIdSerializer.Instance.Serialize(bsonWriter, id.GetType(), id, options);
}
示例7: Serialize
void IBsonSerializable.Serialize(
BsonWriter bsonWriter,
Type nominalType,
bool serializeIdFirst
)
{
Serialize(bsonWriter, nominalType, serializeIdFirst);
}
示例8: WriteBody
protected override void WriteBody(BsonWriter writer)
{
writer.WriteValue(BsonDataType.Integer,0);
writer.WriteString(this.FullCollectionName);
writer.WriteValue(BsonDataType.Integer,this.Flags);
writer.Write(selector);
writer.Write(Document);
}
示例9: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
var c = (C)value;
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("nominalType", nominalType.Name);
bsonWriter.WriteInt32("X", c.X);
bsonWriter.WriteEndDocument();
}
示例10: Serialize
protected override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
bool serializeIdFirst
)
{
document.Serialize(bsonWriter, nominalType, serializeIdFirst);
}
示例11: TestCalculateSizeOfEmptyDoc
public void TestCalculateSizeOfEmptyDoc()
{
Document doc = new Document();
MemoryStream ms = new MemoryStream();
BsonWriter writer = new BsonWriter(ms);
Assert.AreEqual(5,writer.CalculateSize(doc));
}
示例12: Serialize
public void Serialize(
BsonWriter bsonWriter,
Type nominalType, // ignored
bool serializeIdFirst
)
{
BsonSerializer.Serialize(bsonWriter, this.nominalType, obj, serializeIdFirst); // use wrapped nominalType
}
示例13: Serialize
void IBsonSerializable.Serialize(
BsonWriter bsonWriter,
Type nominalType,
IBsonSerializationOptions options
)
{
Serialize(bsonWriter, nominalType, options);
}
示例14: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
int intValue;
if (value is string && int.TryParse((string)value, out intValue))
bsonWriter.WriteInt32(intValue);
else
throw new InvalidOperationException();
}
示例15: Serialize
public void Serialize(
BsonWriter bsonWriter,
Type nominalType, // ignored
IBsonSerializationOptions options
)
{
BsonSerializer.Serialize(bsonWriter, this.nominalType, obj, options); // use wrapped nominalType
}