本文整理汇总了C#中IBsonSerializer.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IBsonSerializer.GetType方法的具体用法?C# IBsonSerializer.GetType怎么用?C# IBsonSerializer.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBsonSerializer
的用法示例。
在下文中一共展示了IBsonSerializer.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyAttribute
// public methods
/// <summary>
/// Apply an attribute to these serialization options and modify the options accordingly.
/// </summary>
/// <param name="serializer">The serializer that these serialization options are for.</param>
/// <param name="attribute">The serialization options attribute.</param>
public override void ApplyAttribute(IBsonSerializer serializer, Attribute attribute)
{
EnsureNotFrozen();
var itemSerializer = serializer.GetItemSerializationInfo().Serializer;
if (_itemSerializationOptions == null)
{
var itemDefaultSerializationOptions = itemSerializer.GetDefaultSerializationOptions();
// special case for legacy collections: allow BsonRepresentation on object
if (itemDefaultSerializationOptions == null &&
(serializer.GetType() == typeof(EnumerableSerializer) || serializer.GetType() == typeof(QueueSerializer) || serializer.GetType() == typeof(StackSerializer)) &&
attribute.GetType() == typeof(BsonRepresentationAttribute))
{
itemDefaultSerializationOptions = new RepresentationSerializationOptions(BsonType.Null); // will be modified later by ApplyAttribute
}
if (itemDefaultSerializationOptions == null)
{
var message = string.Format(
"A serialization options attribute of type {0} cannot be used when the serializer is of type {1} and the item serializer is of type {2}.",
BsonUtils.GetFriendlyTypeName(attribute.GetType()),
BsonUtils.GetFriendlyTypeName(serializer.GetType()),
BsonUtils.GetFriendlyTypeName(itemSerializer.GetType()));
throw new NotSupportedException(message);
}
_itemSerializationOptions = itemDefaultSerializationOptions.Clone();
}
_itemSerializationOptions.ApplyAttribute(itemSerializer, attribute);
}
示例2: Apply
// protected methods
/// <summary>
/// Reconfigures the specified serializer by applying this attribute to it.
/// </summary>
/// <param name="serializer">The serializer.</param>
/// <returns>A reconfigured serializer.</returns>
/// <exception cref="System.NotSupportedException"></exception>
protected virtual IBsonSerializer Apply(IBsonSerializer serializer)
{
// if none of the overrides applied the attribute to the serializer see if it can be applied to a child serializer
var childSerializerConfigurable = serializer as IChildSerializerConfigurable;
if (childSerializerConfigurable != null)
{
var childSerializer = childSerializerConfigurable.ChildSerializer;
var reconfiguredChildSerializer = Apply(childSerializer);
return childSerializerConfigurable.WithChildSerializer(reconfiguredChildSerializer);
}
var message = string.Format(
"A serializer of type '{0}' is not configurable using an attribute of type '{1}'.",
BsonUtils.GetFriendlyTypeName(serializer.GetType()),
BsonUtils.GetFriendlyTypeName(this.GetType()));
throw new NotSupportedException(message);
}
示例3: ApplyAttribute
// public methods
/// <summary>
/// Apply an attribute to these serialization options and modify the options accordingly.
/// </summary>
/// <param name="serializer">The serializer that these serialization options are for.</param>
/// <param name="attribute">The serialization options attribute.</param>
public override void ApplyAttribute(IBsonSerializer serializer, Attribute attribute)
{
EnsureNotFrozen();
var dictionaryOptionsAttribute = attribute as BsonDictionaryOptionsAttribute;
if (dictionaryOptionsAttribute != null)
{
_representation = dictionaryOptionsAttribute.Representation;
return;
}
// for backward compatibility reasons representations Array and Document apply to the Dictionary and not the values
var representationAttribute = attribute as BsonRepresentationAttribute;
if (representationAttribute != null)
{
switch (representationAttribute.Representation)
{
case BsonType.Array:
_representation = DictionaryRepresentation.ArrayOfArrays;
return;
case BsonType.Document:
_representation = DictionaryRepresentation.Document;
return;
}
}
// any other attributes are applied to the values
var valueType = typeof(object);
if (serializer.GetType().IsGenericType)
{
valueType = serializer.GetType().GetGenericArguments()[1]; // TValue
}
var valueSerializer = BsonSerializer.LookupSerializer(valueType);
var valueSerializationOptions = _keyValuePairSerializationOptions.ValueSerializationOptions;
if (valueSerializationOptions == null)
{
var valueDefaultSerializationOptions = valueSerializer.GetDefaultSerializationOptions();
// special case for legacy dictionaries: allow BsonRepresentation on object
if (valueDefaultSerializationOptions == null &&
serializer.GetType() == typeof(DictionarySerializer) &&
attribute.GetType() == typeof(BsonRepresentationAttribute))
{
valueDefaultSerializationOptions = new RepresentationSerializationOptions(BsonType.Null); // will be modified later by ApplyAttribute
}
if (valueDefaultSerializationOptions == null)
{
var message = string.Format(
"A serialization options attribute of type {0} cannot be used when the serializer is of type {1} and the value serializer is of type {2}.",
BsonUtils.GetFriendlyTypeName(attribute.GetType()),
BsonUtils.GetFriendlyTypeName(serializer.GetType()),
BsonUtils.GetFriendlyTypeName(valueSerializer.GetType()));
throw new NotSupportedException(message);
}
valueSerializationOptions = valueDefaultSerializationOptions.Clone();
}
valueSerializationOptions.ApplyAttribute(valueSerializer, attribute);
_keyValuePairSerializationOptions = new KeyValuePairSerializationOptions(
_keyValuePairSerializationOptions.Representation,
_keyValuePairSerializationOptions.KeySerializationOptions,
valueSerializationOptions);
}
示例4: ApplyAttribute
// public methods
/// <summary>
/// Apply an attribute to these serialization options and modify the options accordingly.
/// </summary>
/// <param name="serializer">The serializer that these serialization options are for.</param>
/// <param name="attribute">The serialization options attribute.</param>
public override void ApplyAttribute(IBsonSerializer serializer, Attribute attribute)
{
EnsureNotFrozen();
var dictionaryOptionsAttribute = attribute as BsonDictionaryOptionsAttribute;
if (dictionaryOptionsAttribute != null)
{
_representation = dictionaryOptionsAttribute.Representation;
return;
}
// for backward compatibility reasons representations Array and Document apply to the Dictionary and not the items
var representationAttribute = attribute as BsonRepresentationAttribute;
if (representationAttribute != null)
{
switch (representationAttribute.Representation)
{
case BsonType.Array:
_representation = DictionaryRepresentation.ArrayOfArrays;
return;
case BsonType.Document:
_representation = DictionaryRepresentation.Document;
return;
}
}
var itemSerializer = serializer.GetItemSerializationInfo().Serializer;
if (_itemSerializationOptions == null)
{
var itemDefaultSerializationOptions = itemSerializer.GetDefaultSerializationOptions();
// special case for legacy dictionaries: allow BsonRepresentation on object
if (itemDefaultSerializationOptions == null &&
serializer.GetType() == typeof(DictionarySerializer) &&
attribute.GetType() == typeof(BsonRepresentationAttribute))
{
itemDefaultSerializationOptions = new RepresentationSerializationOptions(BsonType.Null); // will be modified later by ApplyAttribute
}
if (itemDefaultSerializationOptions == null)
{
var message = string.Format(
"A serialization options attribute of type {0} cannot be used when the serializer is of type {1} and the item serializer is of type {2}.",
BsonUtils.GetFriendlyTypeName(attribute.GetType()),
BsonUtils.GetFriendlyTypeName(serializer.GetType()),
BsonUtils.GetFriendlyTypeName(itemSerializer.GetType()));
throw new NotSupportedException(message);
}
_itemSerializationOptions = itemDefaultSerializationOptions.Clone();
}
_itemSerializationOptions.ApplyAttribute(itemSerializer, attribute);
}