本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteStartArray方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteStartArray方法的具体用法?C# BsonWriter.WriteStartArray怎么用?C# BsonWriter.WriteStartArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteStartArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options) {
var dateTimeOffset = (DateTimeOffset)value;
var representationSerializationOptions = EnsureSerializationOptions<RepresentationSerializationOptions>(options);
switch (representationSerializationOptions.Representation) {
case BsonType.Array:
bsonWriter.WriteStartArray();
bsonWriter.WriteInt64(dateTimeOffset.UtcTicks);
bsonWriter.WriteInt32((int)dateTimeOffset.Offset.TotalMinutes);
bsonWriter.WriteEndArray();
break;
case BsonType.Document:
bsonWriter.WriteStartDocument();
bsonWriter.WriteDateTime("DateTime", BsonUtils.ToMillisecondsSinceEpoch(dateTimeOffset.UtcDateTime));
bsonWriter.WriteInt64("Ticks", dateTimeOffset.UtcTicks);
bsonWriter.WriteInt32("Offset", (int)dateTimeOffset.Offset.TotalMinutes);
bsonWriter.WriteEndDocument();
break;
default:
var message = string.Format("'{0}' is not a valid DateTimeOffset representation.", representationSerializationOptions.Representation);
throw new BsonSerializationException(message);
}
}
示例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 coordinates = (GeoJson2DCoordinates)value;
bsonWriter.WriteStartArray();
bsonWriter.WriteDouble(coordinates.X);
bsonWriter.WriteDouble(coordinates.Y);
bsonWriter.WriteEndArray();
}
}
示例4: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
bsonWriter.WriteStartArray();
if (value != null)
{
var array = value as IEnumerable;
if (array != null)
{
foreach (var id in from object arrayItem in array select IdentifierFinder.GetId(arrayItem))
{
BsonSerializer.Serialize(bsonWriter, id.GetType(), id);
}
}
}
bsonWriter.WriteEndArray();
}
示例5: 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 = (GeoJson3DProjectedCoordinates)value;
bsonWriter.WriteStartArray();
bsonWriter.WriteDouble(coordinates.Easting);
bsonWriter.WriteDouble(coordinates.Northing);
bsonWriter.WriteDouble(coordinates.Altitude);
bsonWriter.WriteEndArray();
}
}
示例6: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (_trace)
pb.Trace.WriteLine("ZStringArraySerializer.Serialize()");
if (value == null)
{
throw new PBException("error serialize ZStringArray value is null");
}
string[] stringValues = ((ZStringArray)value).Values;
if (stringValues == null)
bsonWriter.WriteNull();
else
{
bsonWriter.WriteStartArray();
foreach (string stringValue in stringValues)
{
bsonWriter.WriteString(stringValue);
}
bsonWriter.WriteEndArray();
}
}
示例7: 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 actualType = value.GetType();
var discriminator = GetDiscriminator(nominalType, actualType);
if (discriminator != null)
{
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", discriminator);
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options);
bsonWriter.WriteEndDocument();
return;
}
var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;
Type lastItemType = null;
IBsonSerializer lastItemSerializer = null;
bsonWriter.WriteStartArray();
foreach (var item in EnumerateItemsInSerializationOrder(value))
{
var itemType = (item == null) ? typeof(object) : item.GetType();
IBsonSerializer itemSerializer;
if (itemType == lastItemType)
{
itemSerializer = lastItemSerializer;
}
else
{
itemSerializer = BsonSerializer.LookupSerializer(itemType);
lastItemType = itemType;
lastItemSerializer = itemSerializer;
}
itemSerializer.Serialize(bsonWriter, typeof(object), item, itemSerializationOptions);
}
bsonWriter.WriteEndArray();
}
}
示例8: 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 dictionary = (IDictionary)value;
if (nominalType == typeof(object))
{
var actualType = value.GetType();
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", BsonClassMap.GetTypeNameDiscriminator(actualType));
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options); // recursive call replacing nominalType with actualType
bsonWriter.WriteEndDocument();
return;
}
var dictionaryOptions = options as DictionarySerializationOptions;
if (dictionaryOptions == null)
{
// support RepresentationSerializationOptions for backward compatibility
var representationOptions = options as RepresentationSerializationOptions;
if (representationOptions != null)
{
switch (representationOptions.Representation)
{
case BsonType.Array:
dictionaryOptions = DictionarySerializationOptions.ArrayOfArrays;
break;
case BsonType.Document:
dictionaryOptions = DictionarySerializationOptions.Document;
break;
default:
var message = string.Format("BsonType {0} is not a valid representation for a Dictionary.", representationOptions.Representation);
throw new BsonSerializationException(message);
}
}
if (dictionaryOptions == null)
{
dictionaryOptions = DictionarySerializationOptions.Defaults;
}
}
var representation = dictionaryOptions.Representation;
if (representation == DictionaryRepresentation.Dynamic)
{
representation = DictionaryRepresentation.Document;
foreach (object key in dictionary.Keys)
{
var name = key as string; // check for null and type string at the same time
if (name == null || name.StartsWith("$") || name.Contains("."))
{
representation = DictionaryRepresentation.ArrayOfArrays;
break;
}
}
}
switch (representation)
{
case DictionaryRepresentation.Document:
bsonWriter.WriteStartDocument();
foreach (DictionaryEntry entry in dictionary)
{
bsonWriter.WriteName((string)entry.Key);
BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Value);
}
bsonWriter.WriteEndDocument();
break;
case DictionaryRepresentation.ArrayOfArrays:
bsonWriter.WriteStartArray();
foreach (DictionaryEntry entry in dictionary)
{
bsonWriter.WriteStartArray();
BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Key);
BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Value);
bsonWriter.WriteEndArray();
}
bsonWriter.WriteEndArray();
break;
case DictionaryRepresentation.ArrayOfDocuments:
bsonWriter.WriteStartArray();
foreach (DictionaryEntry entry in dictionary)
{
bsonWriter.WriteStartDocument();
bsonWriter.WriteName("k");
BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Key);
bsonWriter.WriteName("v");
//.........这里部分代码省略.........
示例9: WriteStyleParagraphProperties
private static void WriteStyleParagraphProperties(BsonWriter bsonWriter, OXmlStyleParagraphProperties element)
{
if (element.AdjustRightIndent != null)
bsonWriter.WriteBoolean("AdjustRightIndent", (bool)element.AdjustRightIndent);
if (element.AutoSpaceDE != null)
bsonWriter.WriteBoolean("AutoSpaceDE", (bool)element.AutoSpaceDE);
if (element.AutoSpaceDN != null)
bsonWriter.WriteBoolean("AutoSpaceDN", (bool)element.AutoSpaceDN);
if (element.BiDi != null)
bsonWriter.WriteBoolean("BiDi", (bool)element.BiDi);
if (element.ContextualSpacing != null)
bsonWriter.WriteBoolean("ContextualSpacing", (bool)element.ContextualSpacing);
if (element.Justification != null)
bsonWriter.WriteString("Justification", element.Justification.ToString());
if (element.KeepLines != null)
bsonWriter.WriteBoolean("KeepLines", (bool)element.KeepLines);
if (element.KeepNext != null)
bsonWriter.WriteBoolean("KeepNext", (bool)element.KeepNext);
if (element.Kinsoku != null)
bsonWriter.WriteBoolean("Kinsoku", (bool)element.Kinsoku);
if (element.MirrorIndents != null)
bsonWriter.WriteBoolean("MirrorIndents", (bool)element.MirrorIndents);
if (element.OutlineLevel != null)
bsonWriter.WriteInt32("OutlineLevel", (int)element.OutlineLevel);
if (element.OverflowPunctuation != null)
bsonWriter.WriteBoolean("OverflowPunctuation", (bool)element.OverflowPunctuation);
if (element.PageBreakBefore != null)
bsonWriter.WriteBoolean("PageBreakBefore", (bool)element.PageBreakBefore);
if (element.SnapToGrid != null)
bsonWriter.WriteBoolean("SnapToGrid", (bool)element.SnapToGrid);
if (element.SpacingBetweenLines != null)
{
bsonWriter.WriteStartDocument("SpacingBetweenLines");
WriteSpacingBetweenLines(bsonWriter, element.SpacingBetweenLines);
bsonWriter.WriteEndDocument();
}
if (element.SuppressAutoHyphens != null)
bsonWriter.WriteBoolean("SuppressAutoHyphens", (bool)element.SuppressAutoHyphens);
if (element.SuppressLineNumbers != null)
bsonWriter.WriteBoolean("SuppressLineNumbers", (bool)element.SuppressLineNumbers);
if (element.SuppressOverlap != null)
bsonWriter.WriteBoolean("SuppressOverlap", (bool)element.SuppressOverlap);
if (element.Tabs != null)
{
bsonWriter.WriteStartArray("Tabs");
WriteTabs(bsonWriter, element.Tabs);
bsonWriter.WriteEndArray();
}
if (element.TextAlignment != null)
bsonWriter.WriteString("TextAlignment", element.TextAlignment.ToString());
if (element.TextBoxTightWrap != null)
bsonWriter.WriteString("TextBoxTightWrap", element.TextBoxTightWrap.ToString());
if (element.TextDirection != null)
bsonWriter.WriteString("TextDirection", element.TextDirection.ToString());
if (element.TopLinePunctuation != null)
bsonWriter.WriteBoolean("TopLinePunctuation", (bool)element.TopLinePunctuation);
if (element.WidowControl != null)
bsonWriter.WriteBoolean("WidowControl", (bool)element.WidowControl);
if (element.WordWrap != null)
bsonWriter.WriteBoolean("WordWrap", (bool)element.WordWrap);
}
示例10: Serialize
//.........这里部分代码省略.........
else
{
// dont know why nominalType can be an object
if (nominalType == typeof(object))
{
var actualType = value.GetType();
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options); // recursive call replacing nominalType with actualType
bsonWriter.WriteEndDocument();
return;
}
// json Dictionary
// { "toto1" : "tata1", "toto2" : "tata2" }
//var dictionary = (IDictionary)value;
NameValueCollection nameValueCollection = (NameValueCollection)value;
var dictionarySerializationOptions = EnsureSerializationOptions(options);
var dictionaryRepresentation = dictionarySerializationOptions.Representation;
var keyValuePairSerializationOptions = dictionarySerializationOptions.KeyValuePairSerializationOptions;
if (dictionaryRepresentation == DictionaryRepresentation.Dynamic)
{
// if some keys contain '$', '.' or '\0' serialize as ArrayOfArrays otherwise serialize as Document
dictionaryRepresentation = DictionaryRepresentation.Document;
foreach (string key in nameValueCollection.Keys)
{
//var name = key as string; // key might not be a string
if (string.IsNullOrEmpty(key) || key[0] == '$' || key.IndexOf('.') != -1 || key.IndexOf('\0') != -1)
{
dictionaryRepresentation = DictionaryRepresentation.ArrayOfArrays;
break;
}
}
}
switch (dictionaryRepresentation)
{
case DictionaryRepresentation.Document:
bsonWriter.WriteStartDocument();
//foreach (DictionaryEntry dictionaryEntry in dictionary)
//{
// bsonWriter.WriteName((string)dictionaryEntry.Key);
// BsonSerializer.Serialize(bsonWriter, typeof(object), dictionaryEntry.Value, keyValuePairSerializationOptions.ValueSerializationOptions);
//}
for (int i = 0; i < nameValueCollection.Count; i++)
{
bsonWriter.WriteString(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
}
bsonWriter.WriteEndDocument();
break;
case DictionaryRepresentation.ArrayOfArrays:
case DictionaryRepresentation.ArrayOfDocuments:
// override KeyValuePair representation if necessary
var keyValuePairRepresentation = (dictionaryRepresentation == DictionaryRepresentation.ArrayOfArrays) ? BsonType.Array : BsonType.Document;
if (keyValuePairSerializationOptions.Representation != keyValuePairRepresentation)
{
keyValuePairSerializationOptions = new KeyValuePairSerializationOptions(keyValuePairRepresentation, keyValuePairSerializationOptions.KeySerializationOptions,
keyValuePairSerializationOptions.ValueSerializationOptions);
}
bsonWriter.WriteStartArray();
//foreach (DictionaryEntry dictionaryEntry in dictionary)
for (int i = 0; i < nameValueCollection.Count; i++)
{
//var keyValuePair = new KeyValuePair<object, object>(dictionaryEntry.Key, dictionaryEntry.Value);
var keyValuePair = new KeyValuePair<string, string>(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
//_keyValuePairSerializer.Serialize(bsonWriter, typeof(KeyValuePair<object, object>), keyValuePair, keyValuePairSerializationOptions);
_keyValuePairSerializer.Serialize(bsonWriter, typeof(KeyValuePair<string, string>), keyValuePair, keyValuePairSerializationOptions);
}
bsonWriter.WriteEndArray();
//bsonWriter.WriteStartArray();
//for (int i = 0; i < nameValueCollection.Count; i++)
//{
// bsonWriter.WriteStartArray();
// bsonWriter.WriteString(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
// bsonWriter.WriteEndArray();
//}
//bsonWriter.WriteEndArray();
break;
//case DictionaryRepresentation.ArrayOfDocuments:
// bsonWriter.WriteStartArray();
// for (int i = 0; i < nameValueCollection.Count; i++)
// {
// bsonWriter.WriteStartDocument();
// bsonWriter.WriteString(nameValueCollection.GetKey(i), nameValueCollection.Get(i));
// bsonWriter.WriteEndDocument();
// }
// bsonWriter.WriteEndArray();
// break;
default:
var message = string.Format("'{0}' is not a valid IDictionary representation.", dictionaryRepresentation);
throw new BsonSerializationException(message);
}
}
}
示例11: 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
{
if (nominalType == typeof(object))
{
var actualType = value.GetType();
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options);
bsonWriter.WriteEndDocument();
return;
}
var items = ((Stack)value).ToArray(); // convert to array to allow efficient access in reverse order
var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;
// serialize first pushed item first (reverse of enumeration order)
bsonWriter.WriteStartArray();
for (var i = items.Length - 1; i >= 0; i--)
{
BsonSerializer.Serialize(bsonWriter, typeof(object), items[i], itemSerializationOptions);
}
bsonWriter.WriteEndArray();
}
}
示例12: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
bool serializeIdFirst
) {
// note: the DateTime portion cannot be serialized as a BsonType.DateTime because it is NOT in UTC
var dateTimeOffset = (DateTimeOffset) value;
switch (representation) {
case BsonType.Array:
bsonWriter.WriteStartArray();
bsonWriter.WriteInt64("0", dateTimeOffset.DateTime.Ticks);
bsonWriter.WriteInt32("1", (int) dateTimeOffset.Offset.TotalMinutes);
bsonWriter.WriteEndArray();
break;
case BsonType.String:
bsonWriter.WriteString(XmlConvert.ToString(dateTimeOffset));
break;
default:
throw new BsonInternalException("Unexpected representation");
}
}
示例13: 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)
{
throw new ArgumentNullException("value");
}
var array = (BsonArray)value;
bsonWriter.WriteStartArray();
for (int i = 0; i < array.Count; i++)
{
BsonValueSerializer.Instance.Serialize(bsonWriter, typeof(BsonValue), array[i], null);
}
bsonWriter.WriteEndArray();
}
示例14: 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
{
if (nominalType == typeof(object))
{
var actualType = value.GetType();
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options);
bsonWriter.WriteEndDocument();
return;
}
var items = (Queue)value;
var arraySerializationOptions = EnsureSerializationOptions<ArraySerializationOptions>(options);
var itemSerializationOptions = arraySerializationOptions.ItemSerializationOptions;
bsonWriter.WriteStartArray();
foreach (var item in items)
{
BsonSerializer.Serialize(bsonWriter, typeof(object), item, itemSerializationOptions);
}
bsonWriter.WriteEndArray();
}
}
示例15: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (_trace)
pb.Trace.WriteLine("WebHeaderSerializer.Serialize()");
if (value == null)
{
bsonWriter.WriteNull();
}
else
{
if (nominalType == typeof(object))
{
var actualType = value.GetType();
bsonWriter.WriteStartDocument();
bsonWriter.WriteString("_t", TypeNameDiscriminator.GetDiscriminator(actualType));
bsonWriter.WriteName("_v");
Serialize(bsonWriter, actualType, value, options); // recursive call replacing nominalType with actualType
bsonWriter.WriteEndDocument();
return;
}
var headers = (WebHeaderCollection)value;
bsonWriter.WriteStartDocument();
for (int i = 0; i < headers.Count; i++)
{
bsonWriter.WriteName(headers.GetKey(i));
string[] headerValues = headers.GetValues(i);
if (headerValues.Length == 1)
bsonWriter.WriteString(headerValues[0]);
else
{
bsonWriter.WriteStartArray();
foreach (string headerValue in headerValues)
{
bsonWriter.WriteString(headerValue);
}
bsonWriter.WriteEndArray();
}
}
bsonWriter.WriteEndDocument();
}
}