本文整理汇总了C#中MongoDB.Bson.IO.BsonWriter.WriteEndArray方法的典型用法代码示例。如果您正苦于以下问题:C# BsonWriter.WriteEndArray方法的具体用法?C# BsonWriter.WriteEndArray怎么用?C# BsonWriter.WriteEndArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonWriter
的用法示例。
在下文中一共展示了BsonWriter.WriteEndArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: Serialize
public override void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options)
{
if (value == null)
{
bsonWriter.WriteNull();
return;
}
var serializer = new StringSerializer();
var nvc = (NameValueCollection) value;
bsonWriter.WriteStartArray();
foreach (var key in nvc.AllKeys)
{
foreach (var val in nvc.GetValues(key))
{
bsonWriter.WriteStartArray();
serializer.Serialize(bsonWriter, typeof (string), key, options);
serializer.Serialize(bsonWriter, typeof (string), val, options);
bsonWriter.WriteEndArray();
}
}
bsonWriter.WriteEndArray();
}
示例3: 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();
}
示例4: 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();
}
}
示例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
{
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();
}
}
示例8: 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);
}
}
}
示例9: 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();
}
示例10: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options
)
{
if (value == null) {
bsonWriter.WriteNull();
} else {
var dictionary = (IDictionary) value;
if (dictionary.Keys.Cast<object>().All(o => o.GetType() == typeof(string))) {
bsonWriter.WriteStartDocument();
int index = 0;
foreach (DictionaryEntry entry in dictionary) {
bsonWriter.WriteName((string) entry.Key);
BsonSerializer.Serialize(bsonWriter, typeof(object), entry.Value);
index++;
}
bsonWriter.WriteEndDocument();
} else {
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();
}
}
}
示例11: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
IBsonSerializationOptions options
) {
var decimalValue = (Decimal) value;
var representation = (options == null) ? BsonType.String : ((RepresentationSerializationOptions) options).Representation;
switch (representation) {
case BsonType.Array:
bsonWriter.WriteStartArray();
var bits = Decimal.GetBits(decimalValue);
bsonWriter.WriteInt32("0", bits[0]);
bsonWriter.WriteInt32("1", bits[1]);
bsonWriter.WriteInt32("2", bits[2]);
bsonWriter.WriteInt32("3", bits[3]);
bsonWriter.WriteEndArray();
break;
case BsonType.String:
bsonWriter.WriteString(XmlConvert.ToString(decimalValue));
break;
default:
var message = string.Format("'{0}' is not a valid representation for type 'Decimal'", representation);
throw new BsonSerializationException(message);
}
}
示例12: SerializePolygon
private static void SerializePolygon(BsonWriter bsonWriter, OXmlPolygon polygon)
{
bsonWriter.WriteStartDocument("Polygon");
if (polygon.StartPoint != null)
{
bsonWriter.WriteInt64("StartPointX", polygon.StartPoint.X);
bsonWriter.WriteInt64("StartPointY", polygon.StartPoint.Y);
}
bsonWriter.WriteStartArray("LinesTo");
foreach (OXmlPoint2DType lineTo in polygon.LinesTo)
{
bsonWriter.WriteStartDocument();
bsonWriter.WriteInt64("X", lineTo.X);
bsonWriter.WriteInt64("Y", lineTo.Y);
bsonWriter.WriteEndDocument();
}
bsonWriter.WriteEndArray();
if (polygon.Edited != null)
bsonWriter.WriteBoolean("Edited", (bool)polygon.Edited);
bsonWriter.WriteEndDocument();
}
示例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)
{
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 dictionary = (IDictionary)value;
var dictionarySerializationOptions = EnsureSerializationOptions(options);
var dictionaryRepresentation = dictionarySerializationOptions.Representation;
var keyValuePairSerializationOptions = dictionarySerializationOptions.KeyValuePairSerializationOptions;
if (dictionaryRepresentation == DictionaryRepresentation.Dynamic)
{
dictionaryRepresentation = DictionaryRepresentation.Document;
foreach (object key in dictionary.Keys)
{
var name = key as string; // key might not be a string
if (name == null || (name.Length > 0 && name[0] == '$') || name.IndexOf('.') != -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);
}
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)
{
var keyValuePair = new KeyValuePair<object, object>(dictionaryEntry.Key, dictionaryEntry.Value);
_keyValuePairSerializer.Serialize(
bsonWriter,
typeof(KeyValuePair<object, object>),
keyValuePair,
keyValuePairSerializationOptions);
}
bsonWriter.WriteEndArray();
break;
default:
var message = string.Format("'{0}' is not a valid IDictionary representation.", dictionaryRepresentation);
throw new BsonSerializationException(message);
}
}
}
示例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
{
bsonWriter.WriteStartArray();
foreach (var element in (Queue)value)
{
BsonSerializer.Serialize(bsonWriter, typeof(object), element);
}
bsonWriter.WriteEndArray();
}
}
示例15: Serialize
public override void Serialize(
BsonWriter bsonWriter,
Type nominalType,
object value,
bool serializeIdFirst
)
{
if (value == null) {
bsonWriter.WriteNull();
} else {
bsonWriter.WriteStartArray();
int index = 0;
foreach (var element in (IEnumerable) value) {
bsonWriter.WriteName(index.ToString());
BsonSerializer.Serialize(bsonWriter, typeof(object), element);
index++;
}
bsonWriter.WriteEndArray();
}
}