本文整理汇总了C#中MongoDB.Bson.IO.BsonReader.ReadEndArray方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.ReadEndArray方法的具体用法?C# BsonReader.ReadEndArray怎么用?C# BsonReader.ReadEndArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonReader
的用法示例。
在下文中一共展示了BsonReader.ReadEndArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
object value = null;
if (bsonReader.CurrentBsonType == BsonType.Null)
{
bsonReader.ReadNull();
}
else
{
bsonReader.ReadStartArray();
var idList = new List<ObjectId>();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var id = (ObjectId)BsonSerializer.Deserialize(bsonReader, typeof(ObjectId));
idList.Add(id);
}
bsonReader.ReadEndArray();
if (idList.Count > 0)
{
var cursor = MongoDbProvider.Database.GetCollection(DocumentType, DocumentType.Name)
.FindAs(DocumentType, Query.In("_id", BsonArray.Create(idList)));
var documents = (IList)Activator.CreateInstance(typeof(List<>).MakeGenericType(DocumentType));
foreach (var document in cursor)
{
documents.Add(document);
}
value = documents;
}
}
return value;
}
示例2: Deserialize
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
IBsonSerializationOptions options
)
{
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
var nvc = new NameValueCollection();
bsonReader.ReadStartArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
bsonReader.ReadStartArray();
var key = (string)StringSerializer.Instance.Deserialize(bsonReader, typeof(string), options);
var val = (string)StringSerializer.Instance.Deserialize(bsonReader, typeof(string), options);
bsonReader.ReadEndArray();
nvc.Add(key, val);
}
bsonReader.ReadEndArray();
return nvc;
}
示例3: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>An object.</returns>
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
VerifyTypes(nominalType, actualType, typeof(DateTimeOffset));
BsonType bsonType = bsonReader.GetCurrentBsonType();
long ticks;
TimeSpan offset;
switch (bsonType)
{
case BsonType.Array:
bsonReader.ReadStartArray();
ticks = bsonReader.ReadInt64();
offset = TimeSpan.FromMinutes(bsonReader.ReadInt32());
bsonReader.ReadEndArray();
return new DateTimeOffset(ticks, offset);
case BsonType.Document:
bsonReader.ReadStartDocument();
bsonReader.ReadDateTime("DateTime"); // ignore value
ticks = bsonReader.ReadInt64("Ticks");
offset = TimeSpan.FromMinutes(bsonReader.ReadInt32("Offset"));
bsonReader.ReadEndDocument();
return new DateTimeOffset(ticks, offset);
case BsonType.String:
return XmlConvert.ToDateTimeOffset(bsonReader.ReadString());
default:
var message = string.Format("Cannot deserialize DateTimeOffset from BsonType {0}.", bsonType);
throw new Exception(message);
}
}
示例4: Deserialize
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
if (_trace)
pb.Trace.WriteLine("ZStringArraySerializer.Deserialize()");
VerifyTypes(nominalType, actualType, typeof(ZStringArray));
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Array:
bsonReader.ReadStartArray();
//return new ZString(bsonReader.ReadString());
var array = new List<string>();
bsonType = bsonReader.ReadBsonType();
while (bsonType != BsonType.EndOfDocument)
{
if (bsonType != BsonType.String)
throw new PBException("error ZStringArray cannot contain value of type {0}", bsonType);
var value = bsonReader.ReadString();
array.Add(value);
bsonType = bsonReader.ReadBsonType();
}
bsonReader.ReadEndArray();
return new ZStringArray(array.ToArray());
default:
throw new PBException("error cannot deserialize ZStringArray from BsonType {0}.", bsonType);
}
}
示例5: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>An object.</returns>
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
VerifyTypes(nominalType, actualType, typeof(BsonArray));
var bsonType = bsonReader.GetCurrentBsonType();
switch (bsonType)
{
case BsonType.Array:
bsonReader.ReadStartArray();
var array = new BsonArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var value = (BsonValue)BsonValueSerializer.Instance.Deserialize(bsonReader, typeof(BsonValue), null);
array.Add(value);
}
bsonReader.ReadEndArray();
return array;
default:
var message = string.Format("Cannot deserialize BsonArray from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例6: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>An object.</returns>
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else if (bsonType == BsonType.Array)
{
bsonReader.ReadStartArray();
var list = new ArrayList();
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var elementType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var serializer = BsonSerializer.LookupSerializer(elementType);
var element = serializer.Deserialize(bsonReader, typeof(object), elementType, null);
list.Add(element);
}
bsonReader.ReadEndArray();
return list;
}
else
{
var message = string.Format("Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType);
throw new FileFormatException(message);
}
}
示例7: TestArrayEmpty
public void TestArrayEmpty() {
var json = "[]";
using (bsonReader = BsonReader.Create(json)) {
Assert.AreEqual(BsonType.Array, bsonReader.ReadBsonType());
bsonReader.ReadStartArray();
Assert.AreEqual(BsonType.EndOfDocument, bsonReader.ReadBsonType());
bsonReader.ReadEndArray();
Assert.AreEqual(BsonReaderState.Done, bsonReader.State);
}
Assert.AreEqual(json, BsonSerializer.Deserialize<BsonArray>(new StringReader(json)).ToJson());
}
示例8: ReadArray
static IList ReadArray(BsonReader bsonReader)
{
var array = new ArrayList();
bsonReader.ReadStartArray();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
array.Add(ReadObject(bsonReader));
bsonReader.ReadEndArray();
return array;
}
示例9: TestArrayOneElement
public void TestArrayOneElement()
{
var json = "[1]";
using (_bsonReader = new JsonReader(json))
{
Assert.AreEqual(BsonType.Array, _bsonReader.ReadBsonType());
_bsonReader.ReadStartArray();
Assert.AreEqual(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.AreEqual(1, _bsonReader.ReadInt32());
Assert.AreEqual(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
_bsonReader.ReadEndArray();
Assert.AreEqual(BsonReaderState.Done, _bsonReader.State);
}
Assert.AreEqual(json, BsonSerializer.Deserialize<BsonArray>(json).ToJson());
}
示例10: TestArrayTwoElements
public void TestArrayTwoElements()
{
var json = "[1, 2]";
using (_bsonReader = BsonReader.Create(json))
{
Assert.AreEqual(BsonType.Array, _bsonReader.ReadBsonType());
_bsonReader.ReadStartArray();
Assert.AreEqual(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.AreEqual(1, _bsonReader.ReadInt32());
Assert.AreEqual(BsonType.Int32, _bsonReader.ReadBsonType());
Assert.AreEqual(2, _bsonReader.ReadInt32());
Assert.AreEqual(BsonType.EndOfDocument, _bsonReader.ReadBsonType());
_bsonReader.ReadEndArray();
Assert.AreEqual(BsonReaderState.Done, _bsonReader.State);
}
Assert.AreEqual(json, BsonSerializer.Deserialize<BsonArray>(new StringReader(json)).ToJson());
}
示例11: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>
/// An object.
/// </returns>
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
if (bsonReader.GetCurrentBsonType() == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else
{
bsonReader.ReadStartArray();
var longitude = bsonReader.ReadDouble();
var latitude = bsonReader.ReadDouble();
bsonReader.ReadEndArray();
return new GeoJson2DGeographicCoordinates(longitude, latitude);
}
}
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:28,代码来源:GeoJson2DGeographicCoordinatesSerializer.cs
示例12: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>
/// An object.
/// </returns>
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
if (bsonReader.GetCurrentBsonType() == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else
{
bsonReader.ReadStartArray();
var easting = bsonReader.ReadDouble();
var northing = bsonReader.ReadDouble();
bsonReader.ReadEndArray();
return new GeoJson2DProjectedCoordinates(easting, northing);
}
}
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:28,代码来源:GeoJson2DProjectedCoordinatesSerializer.cs
示例13: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>
/// An object.
/// </returns>
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
if (bsonReader.GetCurrentBsonType() == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else
{
bsonReader.ReadStartArray();
var x = (double)__doubleSerializer.Deserialize(bsonReader, typeof(double), null);
var y = (double)__doubleSerializer.Deserialize(bsonReader, typeof(double), null);
bsonReader.ReadEndArray();
return new GeoJson2DCoordinates(x, y);
}
}
示例14: TestNestedArray
public void TestNestedArray() {
var json = "{ \"a\" : [1, 2] }";
using (bsonReader = BsonReader.Create(json)) {
Assert.AreEqual(BsonType.Document, bsonReader.ReadBsonType());
bsonReader.ReadStartDocument();
Assert.AreEqual(BsonType.Array, bsonReader.ReadBsonType());
Assert.AreEqual("a", bsonReader.ReadName());
bsonReader.ReadStartArray();
Assert.AreEqual(1, bsonReader.ReadInt32());
Assert.AreEqual(2, bsonReader.ReadInt32());
bsonReader.ReadEndArray();
bsonReader.ReadEndDocument();
Assert.AreEqual(BsonReaderState.Done, bsonReader.State);
}
Assert.AreEqual(json, BsonSerializer.Deserialize<BsonDocument>(new StringReader(json)).ToJson());
}
示例15: Deserialize
// public methods
/// <summary>
/// Deserializes an object from a BsonReader.
/// </summary>
/// <param name="bsonReader">The BsonReader.</param>
/// <param name="nominalType">The nominal type of the object.</param>
/// <param name="actualType">The actual type of the object.</param>
/// <param name="options">The serialization options.</param>
/// <returns>An object.</returns>
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
Type actualType,
IBsonSerializationOptions options)
{
var dictionarySerializationOptions = EnsureSerializationOptions(options);
var itemSerializationOptions = dictionarySerializationOptions.ItemSerializationOptions;
var bsonType = bsonReader.GetCurrentBsonType();
if (bsonType == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else if (bsonType == BsonType.Document)
{
if (nominalType == typeof(object))
{
bsonReader.ReadStartDocument();
bsonReader.ReadString("_t"); // skip over discriminator
bsonReader.ReadName("_v");
var value = Deserialize(bsonReader, actualType, options); // recursive call replacing nominalType with actualType
bsonReader.ReadEndDocument();
return value;
}
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartDocument();
var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var key = bsonReader.ReadName();
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, itemSerializationOptions);
dictionary.Add(key, value);
}
bsonReader.ReadEndDocument();
return dictionary;
}
else if (bsonType == BsonType.Array)
{
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartArray();
var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var keyValuePairBsonType = bsonReader.GetCurrentBsonType();
if (keyValuePairBsonType == BsonType.Array)
{
bsonReader.ReadStartArray();
bsonReader.ReadBsonType();
var keyType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var keySerializer = BsonSerializer.LookupSerializer(keyType);
var key = keySerializer.Deserialize(bsonReader, typeof(object), keyType, null); // no serialization options for key
bsonReader.ReadBsonType();
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, itemSerializationOptions);
bsonReader.ReadEndArray();
dictionary.Add(key, value);
}
else if (keyValuePairBsonType == BsonType.Document)
{
bsonReader.ReadStartDocument();
object key = null;
object value = null;
bool keyFound = false, valueFound = false;
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var name = bsonReader.ReadName();
switch (name)
{
case "k":
var keyType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var keySerializer = BsonSerializer.LookupSerializer(keyType);
key = keySerializer.Deserialize(bsonReader, typeof(object), keyType, null); // no serialization options for key
keyFound = true;
break;
case "v":
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, itemSerializationOptions);
valueFound = true;
break;
default:
var message = string.Format("Element '{0}' is not valid for Dictionary items (expecting 'k' or 'v').", name);
throw new FileFormatException(message);
}
}
//.........这里部分代码省略.........