本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteNull方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteNull方法的具体用法?C# BsonWriter.WriteNull怎么用?C# BsonWriter.WriteNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
return;
}
var metaObject = ((IDynamicMetaObjectProvider)value).GetMetaObject(Expression.Constant(value));
var memberNames = metaObject.GetDynamicMemberNames().ToList();
if (memberNames.Count == 0)
{
bsonWriter.WriteNull();
return;
}
bsonWriter.WriteStartDocument();
foreach (var memberName in memberNames)
{
bsonWriter.WriteName(memberName);
var memberValue = BinderHelper.GetMemberValue(value, memberName);
if (memberValue == null)
bsonWriter.WriteNull();
else
{
var memberType = memberValue.GetType();
var serializer = BsonSerializer.LookupSerializer(memberType);
serializer.Serialize(bsonWriter, memberType, memberValue, options);
}
}
bsonWriter.WriteEndDocument();
}
示例2: 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();
}
示例3: Serialize
/// <summary>
/// Serializes an object to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The BsonWriter.</param>
/// <param name="nominalType">The nominal type.</param>
/// <param name="value">The object.</param>
/// <param name="options">The serialization options.</param>
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var lazyBsonArray = (LazyBsonArray)value;
var slice = lazyBsonArray.Slice;
if (slice == null)
{
BsonArraySerializer.Instance.Serialize(bsonWriter, typeof(BsonArray), lazyBsonArray, options);
}
else
{
using (var clonedSlice = slice.GetSlice(0, slice.Length))
{
bsonWriter.WriteRawBsonArray(clonedSlice);
}
}
}
}
示例4: 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();
}
示例5: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
ObjectIdSerializer.Instance.Serialize(bsonWriter, nominalType, IdentifierFinder.GetId(value), options);
}
}
示例6: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var attachment = (Attachment)value;
ObjectIdSerializer.Instance.Serialize(bsonWriter, nominalType, attachment.ID, options);
}
}
示例7: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType,
object value, IBsonSerializationOptions options)
{
if (value != null)
{
bsonWriter.WriteString(value.ToString());
}
else
{
bsonWriter.WriteNull();
}
}
示例8: Serialize
#pragma warning restore 618
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
bool serializeIdFirst
) {
if (value == null) {
bsonWriter.WriteNull();
} else {
bsonWriter.WriteBinaryData((byte[]) value, BsonBinarySubType.Binary);
}
}
示例9: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var actualType = value.GetType();
var actualTypeSerializer = BsonSerializer.LookupSerializer(actualType);
actualTypeSerializer.Serialize(bsonWriter, nominalType, value, options);
}
}
示例10: WriteNullableDouble
protected void WriteNullableDouble(BsonWriter writer,string name,double? value)
{
writer.WriteName(name);
if ( value != null )
{
writer.WriteDouble(value.Value);
}
else
{
writer.WriteNull();
}
}
示例11: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
bool serializeIdFirst
)
{
if (value == null) {
bsonWriter.WriteNull();
} else {
((BsonArray) value).WriteTo(bsonWriter);
}
}
示例12: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
bool serializeIdFirst
)
{
if (value == null) {
bsonWriter.WriteNull();
} else {
Type underlyingType = Nullable.GetUnderlyingType(nominalType);
BsonSerializer.Serialize(bsonWriter, underlyingType, value, serializeIdFirst);
}
}
示例13: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
throw new PBException("error serialize UrlImage value is null");
}
//bsonWriter.WriteString(((WebImage)value).Url);
string url = ((WebImage)value).Url;
if (url != null)
bsonWriter.WriteString(url);
else
bsonWriter.WriteNull();
}
示例14: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
// when entry is null, do not throw, just write null
if (value == null)
{
bsonWriter.WriteNull();
return;
}
if (_failOnSerialize)
throw new InvalidOperationException();
bsonWriter.WriteString((string)value);
}
示例15: Serialize
/// <summary>
/// Serializes an object to a BsonWriter.
/// </summary>
/// <param name="bsonWriter">The BsonWriter.</param>
/// <param name="nominalType">The nominal type.</param>
/// <param name="value">The object.</param>
/// <param name="options">The serialization options.</param>
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
var coordinates = (GeoJson2DCoordinates)value;
bsonWriter.WriteStartArray();
bsonWriter.WriteDouble(coordinates.X);
bsonWriter.WriteDouble(coordinates.Y);
bsonWriter.WriteEndArray();
}
}