本文整理汇总了C#中MongoDB.Bson.IO.BsonReader.ReadName方法的典型用法代码示例。如果您正苦于以下问题:C# BsonReader.ReadName方法的具体用法?C# BsonReader.ReadName怎么用?C# BsonReader.ReadName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Bson.IO.BsonReader
的用法示例。
在下文中一共展示了BsonReader.ReadName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _Deserialize
public OXmlParagraphElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
{
OXmlParagraphElement paragraph = new OXmlParagraphElement();
while (true)
{
BsonType bsonType = bsonReader.ReadBsonType();
if (bsonType == BsonType.EndOfDocument)
break;
//if (bsonType != BsonType.String)
// throw new PBException("error ZStringArray cannot contain value of type {0}", bsonType);
//var value = bsonReader.ReadString();
string name = bsonReader.ReadName();
switch (name.ToLower())
{
case "type":
if (bsonType != BsonType.String)
throw new PBException($"wrong type value {bsonType}");
string type = bsonReader.ReadString();
if (type.ToLower() != "paragraph")
throw new PBException($"invalid Type {type} when deserialize OXmlParagraphElement");
break;
case "style":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.String)
throw new PBException($"wrong style value {bsonType}");
paragraph.Style = bsonReader.ReadString();
break;
default:
throw new PBException($"unknow Paragraph value \"{name}\"");
}
}
return paragraph;
}
示例2: ReadPageSize
private static OXmlPageSize ReadPageSize(BsonReader bsonReader)
{
bsonReader.ReadStartDocument();
OXmlPageSize value = new OXmlPageSize();
while (true)
{
BsonType bsonType = bsonReader.ReadBsonType();
if (bsonType == BsonType.EndOfDocument)
break;
string name = bsonReader.ReadName();
switch (name.ToLower())
{
case "width":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Int32)
throw new PBException($"wrong PageSize width value {bsonType}");
value.Width = bsonReader.ReadInt32();
break;
case "height":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Int32)
throw new PBException($"wrong PageSize height value {bsonType}");
value.Height = bsonReader.ReadInt32();
break;
default:
throw new PBException($"unknow PageSize value \"{name}\"");
}
}
bsonReader.ReadEndDocument();
return value;
}
示例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(BsonNull));
var bsonType = bsonReader.GetCurrentBsonType();
string message;
switch (bsonType)
{
case BsonType.Null:
bsonReader.ReadNull();
return BsonNull.Value;
case BsonType.Document:
bsonReader.ReadStartDocument();
var name = bsonReader.ReadName();
if (name == "_csharpnull" || name == "$csharpnull")
{
var csharpNull = bsonReader.ReadBoolean();
bsonReader.ReadEndDocument();
return csharpNull ? null : BsonNull.Value;
}
else
{
message = string.Format("Unexpected element name while deserializing a BsonNull: {0}.", name);
throw new FileFormatException(message);
}
default:
message = string.Format("Cannot deserialize BsonNull from BsonType {0}.", bsonType);
throw new FileFormatException(message);
}
}
示例4: _Deserialize
public OXmlSimpleFieldElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
{
OXmlSimpleFieldElement element = new OXmlSimpleFieldElement();
while (true)
{
BsonType bsonType = bsonReader.ReadBsonType();
if (bsonType == BsonType.EndOfDocument)
break;
string name = bsonReader.ReadName();
switch (name.ToLower())
{
case "type":
if (bsonType != BsonType.String)
throw new PBException($"wrong type value {bsonType}");
string type = bsonReader.ReadString();
if (type.ToLower() != "simplefield")
throw new PBException($"invalid Type {type} when deserialize OXmlSimpleFieldElement");
break;
case "instruction":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.String)
throw new PBException($"wrong Instruction value {bsonType}");
element.Instruction = bsonReader.ReadString();
break;
default:
throw new PBException($"unknow SimpleField value \"{name}\"");
}
}
return element;
}
示例5: _Deserialize
public OXmlOpenHeaderElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
{
OXmlOpenHeaderElement element = new OXmlOpenHeaderElement();
while (true)
{
BsonType bsonType = bsonReader.ReadBsonType();
if (bsonType == BsonType.EndOfDocument)
break;
string name = bsonReader.ReadName();
switch (name.ToLower())
{
case "type":
if (bsonType != BsonType.String)
throw new PBException($"wrong type value {bsonType}");
string type = bsonReader.ReadString();
//"openfooter"
if (type.ToLower() != "openheader")
throw new PBException($"invalid Type {type} when deserialize OXmlOpenHeader");
break;
case "headertype":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.String)
throw new PBException($"wrong HeaderType value {bsonType}");
element.HeaderType = bsonReader.ReadString().zParseEnum<HeaderFooterValues>();
break;
default:
//OpenHeaderFooter
throw new PBException($"unknow OpenHeader value \"{name}\"");
}
}
return element;
}
示例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)
{
if (bsonReader.GetCurrentBsonType() == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else
{
bsonReader.ReadStartDocument();
DeserializeType(bsonReader, "link");
bsonReader.ReadName("properties");
bsonReader.ReadStartDocument();
var href = bsonReader.ReadString("href");
string hrefType = null;
if (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
hrefType = bsonReader.ReadString("type");
}
bsonReader.ReadEndDocument();
bsonReader.ReadEndDocument();
return new GeoJsonLinkedCoordinateReferenceSystem(href, hrefType);
}
}
开发者ID:Khosrow-Azizi,项目名称:MasterExperimentV2,代码行数:36,代码来源:GeoJsonLinkedCoordinateReferenceSystemSerializer.cs
示例7: Deserialize
public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
bsonReader.ReadStartDocument();
bsonReader.ReadName();
var typeName = bsonReader.ReadString();
bsonReader.ReadName();
var methodSignature = bsonReader.ReadString();
bsonReader.ReadEndDocument();
var type = Type.GetType(typeName);
if (type != null)
{
var method = type.GetMethods().Where(m => GetMethodSignature(m) == methodSignature).SingleOrDefault();
return method;
}
return null;
}
示例8: ReadNullableDouble
protected double? ReadNullableDouble(BsonReader reader,string name)
{
reader.ReadName(name);
var type = reader.GetCurrentBsonType();
if ( type == BsonType.Null)
{
reader.ReadNull();
return null;
}
return reader.ReadDouble();
}
示例9: Deserialize
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
IBsonSerializationOptions options
)
{
var bsonType = bsonReader.CurrentBsonType;
if (bsonType == BsonType.Null) {
bsonReader.ReadNull();
return null;
} else if (bsonType == BsonType.Document) {
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartDocument();
var discriminatorConvention = BsonDefaultSerializer.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, null);
dictionary.Add(key, value);
}
bsonReader.ReadEndDocument();
return dictionary;
} else if (bsonType == BsonType.Array) {
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartArray();
var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument) {
bsonReader.SkipName();
bsonReader.ReadStartArray();
bsonReader.ReadBsonType();
bsonReader.SkipName();
var keyType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var keySerializer = BsonSerializer.LookupSerializer(keyType);
var key = keySerializer.Deserialize(bsonReader, typeof(object), keyType, null);
bsonReader.ReadBsonType();
bsonReader.SkipName();
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
bsonReader.ReadEndArray();
dictionary.Add(key, value);
}
bsonReader.ReadEndArray();
return dictionary;
} else {
var message = string.Format("Can't deserialize a {0} from BsonType {1}", nominalType.FullName, bsonType);
throw new FileFormatException(message);
}
}
示例10: ReadCustomObject
static PSObject ReadCustomObject(BsonReader bsonReader)
{
var ps = new PSObject();
var properties = ps.Properties;
bsonReader.ReadStartDocument();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var name = bsonReader.ReadName();
var value = ReadObject(bsonReader);
properties.Add(new PSNoteProperty(name, value), true); //! true is faster
}
bsonReader.ReadEndDocument();
return ps;
}
示例11: Deserialize
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.Document)
{
var dictionary = CreateInstance(nominalType);
bsonReader.ReadStartDocument();
var discriminatorConvention = BsonSerializer.LookupDiscriminatorConvention(typeof(object));
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var key = bsonReader.ReadName();
//TODO:对键进行字符串留用.Intern.
if (key.Length < 16)
{
key = String.Intern(key);
}
var valueType = discriminatorConvention.GetActualType(bsonReader, typeof(object));
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var value = valueSerializer.Deserialize(bsonReader, typeof(object), valueType, null);
//dictionary.Add(key, value);
if (dictionary is IDictionary<string, object>)
{
((IDictionary<string, object>)dictionary).Add(key, value);
}
else if (dictionary is IDictionary)
{
((IDictionary)dictionary).Add(key, value);
}
}
bsonReader.ReadEndDocument();
return dictionary;
}
else
{
var message = string.Format("Can't deserialize a {0} from BsonType {1}", nominalType.FullName, bsonType);
throw new FileFormatException(message);
}
}
示例12: Deserialize
public override object Deserialize(
BsonReader bsonReader,
Type nominalType,
IBsonSerializationOptions options
)
{
var nvc = new NameValueCollection();
bsonReader.ReadStartDocument();
while (bsonReader.ReadBsonType() != BsonType.EndOfDocument)
{
var name = bsonReader.ReadName().Replace("__period__", ".");
var value = bsonReader.ReadString();
nvc.Add(name, value);
}
bsonReader.ReadEndDocument();
return nvc;
}
示例13: Deserialize
public override object Deserialize( BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options )
{
BsonType bsonType = bsonReader.CurrentBsonType;
object result;
if( bsonType == BsonType.Null )
{
bsonReader.ReadNull();
result = null;
}
else
{
if( bsonType == BsonType.Document )
{
var dictionary = new DynamicDictionary();
bsonReader.ReadStartDocument();
IDiscriminatorConvention valueDiscriminatorConvention = BsonSerializer.LookupDiscriminatorConvention( typeof( object ) );
while( bsonReader.ReadBsonType() != BsonType.EndOfDocument )
{
string key = bsonReader.ReadName();
Type valueType = valueDiscriminatorConvention.GetActualType( bsonReader, typeof( object ) );
IBsonSerializer valueSerializer = BsonSerializer.LookupSerializer( valueType );
object value = valueSerializer.Deserialize( bsonReader, typeof( object ), valueType, null );
if( key != "_t" )
{
dictionary.Add( key.Replace( '\x03', '.' ), value );
}
}
bsonReader.ReadEndDocument();
result = dictionary;
}
else
{
string message = string.Format( "Can't deserialize a {0} from BsonType {1}.", nominalType.FullName, bsonType );
throw new BsonException( message );
}
}
return result;
}
示例14: _Deserialize
public OXmlDocSectionElement _Deserialize(BsonReader bsonReader, IBsonSerializationOptions options)
{
OXmlDocSectionElement element = new OXmlDocSectionElement();
while (true)
{
BsonType bsonType = bsonReader.ReadBsonType();
if (bsonType == BsonType.EndOfDocument)
break;
string name = bsonReader.ReadName();
switch (name.ToLower())
{
case "type":
if (bsonType != BsonType.String)
throw new PBException($"wrong type value {bsonType}");
string type = bsonReader.ReadString();
if (type.ToLower() != "docsection")
throw new PBException($"invalid Type {type} when deserialize OXmlDocSectionElement");
break;
case "pagesize":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Document)
throw new PBException($"wrong PageSize value {bsonType}");
element.PageSize = ReadPageSize(bsonReader);
break;
case "pagemargin":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Document)
throw new PBException($"wrong PageMargin value {bsonType}");
element.PageMargin = ReadPageMargin(bsonReader);
break;
case "pagenumberstart":
if (bsonType == BsonType.Null)
break;
if (bsonType != BsonType.Int32)
throw new PBException($"wrong PageNumberStart value {bsonType}");
element.PageNumberStart = bsonReader.ReadInt32();
break;
default:
throw new PBException($"unknow DocSection value \"{name}\"");
}
}
return element;
}
示例15: Deserialize
// public methods
public override object Deserialize(BsonReader bsonReader, Type nominalType, Type actualType, IBsonSerializationOptions options)
{
if (bsonReader.GetCurrentBsonType() == BsonType.Null)
{
bsonReader.ReadNull();
return null;
}
else
{
bsonReader.ReadStartDocument();
DeserializeType(bsonReader, "name");
bsonReader.ReadName("properties");
bsonReader.ReadStartDocument();
var name = bsonReader.ReadString("name");
bsonReader.ReadEndDocument();
bsonReader.ReadEndDocument();
return new GeoJsonNamedCoordinateReferenceSystem(name);
}
}
开发者ID:pwelter34,项目名称:mongo-csharp-driver,代码行数:21,代码来源:GeoJsonNamedCoordinateReferenceSystemSerializer.cs