public void Apply(BsonMemberMap memberMap) { var memberType = memberMap.MemberType; if (memberType == typeof(T)) { if (!(memberMap.GetSerializer() is IRepresentationConfigurable serializer)) { return; } var serializerWithRepresentation = serializer.WithRepresentation(Representation); memberMap.SetSerializer(serializerWithRepresentation); } else { if (Nullable.GetUnderlyingType(memberType) != typeof(T) || !(memberMap.GetSerializer() is IChildSerializerConfigurable serializer) || !(serializer.ChildSerializer is IRepresentationConfigurable childSerializer)) { return; } var childSerializerWithRepresentation = childSerializer.WithRepresentation(Representation); var serializerWithRepresentation = serializer.WithChildSerializer(childSerializerWithRepresentation); memberMap.SetSerializer(serializerWithRepresentation); } }
/// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { var memberType = memberMap.MemberType; var memberTypeInfo = memberType.GetTypeInfo(); if (memberTypeInfo.IsEnum) { var serializer = memberMap.GetSerializer(); var representationConfigurableSerializer = serializer as IRepresentationConfigurable; if (representationConfigurableSerializer != null) { var reconfiguredSerializer = representationConfigurableSerializer.WithRepresentation(_representation); memberMap.SetSerializer(reconfiguredSerializer); } return; } if (IsNullableEnum(memberType)) { var serializer = memberMap.GetSerializer(); var childSerializerConfigurableSerializer = serializer as IChildSerializerConfigurable; if (childSerializerConfigurableSerializer != null) { var childSerializer = childSerializerConfigurableSerializer.ChildSerializer; var representationConfigurableChildSerializer = childSerializer as IRepresentationConfigurable; if (representationConfigurableChildSerializer != null) { var reconfiguredChildSerializer = representationConfigurableChildSerializer.WithRepresentation(_representation); var reconfiguredSerializer = childSerializerConfigurableSerializer.WithChildSerializer(reconfiguredChildSerializer); memberMap.SetSerializer(reconfiguredSerializer); } } return; } }
/// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { var memberType = memberMap.MemberType; var memberTypeInfo = memberType.GetTypeInfo(); if (memberTypeInfo == typeof(Guid)) { var serializer = memberMap.GetSerializer(); if (serializer is IRepresentationConfigurable representationConfigurableSerializer) { var reconfiguredSerializer = representationConfigurableSerializer.WithRepresentation(Representation); memberMap.SetSerializer(reconfiguredSerializer); } return; } if (IsNullableGuid(memberType)) { var serializer = memberMap.GetSerializer(); if (serializer is IChildSerializerConfigurable childSerializerConfigurableSerializer) { var childSerializer = childSerializerConfigurableSerializer.ChildSerializer; if (childSerializer is IRepresentationConfigurable representationConfigurableChildSerializer) { var reconfiguredChildSerializer = representationConfigurableChildSerializer.WithRepresentation(Representation); var reconfiguredSerializer = childSerializerConfigurableSerializer.WithChildSerializer(reconfiguredChildSerializer); memberMap.SetSerializer(reconfiguredSerializer); } } } }
protected override void writeCurrency(Money instance, BsonWriter writer) { BsonMemberMap currency = _map.GetMemberMap(m => m.CurrencyCode); writer.WriteName("Currency".CapitalizeAs(currency)); currency.GetSerializer(typeof(CurrencyIsoCode)).Serialize(writer, typeof(CurrencyIsoCode), instance.CurrencyCode, currency.SerializationOptions); }
/// <inheritdoc/> public void Apply(BsonMemberMap memberMap) { if (memberMap != memberMap.ClassMap.IdMemberMap) { return; } if (memberMap.MemberType != typeof(string)) { return; } var defaultStringSerializer = BsonSerializer.LookupSerializer(typeof(string)); if (memberMap.GetSerializer() != defaultStringSerializer) { return; } if (memberMap.IdGenerator != null) { return; } memberMap.SetSerializer(new StringSerializer(representation: BsonType.ObjectId)); memberMap.SetIdGenerator(StringObjectIdGenerator.Instance); }
public void Apply(BsonMemberMap memberMap) { Type memberType = memberMap.MemberType; TypeInfo typeInfo = memberType.GetTypeInfo(); if (typeInfo.Name == "Dictionary`2") { Type keyType = typeInfo.GenericTypeArguments[0]; DictionaryRepresentation representation = DictionaryRepresentation.Document; if (keyType != typeof(string)) { representation = DictionaryRepresentation.ArrayOfDocuments; } var serializer = memberMap.GetSerializer(); var dictionaryRepresentationConfigurable = serializer as IDictionaryRepresentationConfigurable; if (dictionaryRepresentationConfigurable != null && dictionaryRepresentationConfigurable.DictionaryRepresentation != representation) { var reconfiguredSerializer = dictionaryRepresentationConfigurable.WithDictionaryRepresentation(representation); memberMap.SetSerializer(reconfiguredSerializer); } return; } }
protected override void writeCurrency(Money value, BsonSerializationContext context, BsonSerializationArgs args) { BsonMemberMap currencyMap = _map.GetMemberMap(m => m.CurrencyCode); context.Writer.WriteName("Currency".CapitalizeAs(currencyMap)); currencyMap.GetSerializer().Serialize(context, args, value.CurrencyCode); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public virtual void Apply(BsonMemberMap memberMap) { var serializer = memberMap.GetSerializer(); var reconfiguredSerializer = Apply(serializer); memberMap.SetSerializer(reconfiguredSerializer); }
private void DeserializeMember(BsonReader bsonReader, object obj, BsonMemberMap memberMap) { try { Type memberType = memberMap.MemberType; Type actualType = bsonReader.CurrentBsonType != BsonType.Null ? BsonDefaultSerializer.LookupDiscriminatorConvention(memberType).GetActualType(bsonReader, memberType) : memberType; object obj1 = memberMap.GetSerializer(actualType).Deserialize(bsonReader, memberType, actualType, memberMap.SerializationOptions); // --- Added if (IsRelation(memberMap)) { ValidateVirtualRelation(memberMap); if (obj1 != null) { if (IsReferencesManyRelation(memberMap)) { ((IDocument)obj).ReferencesManyIDs[memberMap.MemberName] = ((IEnumerable)obj1).Cast <ObjectId>().ToList(); } else { ((IDocument)obj).ReferencesOneIDs[memberMap.MemberName] = (ObjectId)obj1; } } } // --- Added else { memberMap.Setter(obj, obj1); } } catch (Exception ex) { throw new FileFormatException(string.Format("An error occurred while deserializing the {0} {1} of class {2}: {3}", (object)memberMap.MemberName, memberMap.MemberInfo.MemberType == MemberTypes.Field ? (object)"field" : (object)"property", (object)obj.GetType().FullName, (object)ex.Message), ex); } }
public void Apply(BsonMemberMap memberMap) { var info = memberMap.MemberType.GetTypeInfo(); if (info != typeof(T) && info != typeof(T?)) { return; } var serializer = memberMap.GetSerializer(); var serializerConfig = serializer as IRepresentationConfigurable; if (serializerConfig != null) { memberMap.SetSerializer(serializerConfig.WithRepresentation(toType)); } else { var childSerializer = serializer as IChildSerializerConfigurable; if (childSerializer == null) { return; } serializerConfig = childSerializer.ChildSerializer as IRepresentationConfigurable; if (serializerConfig == null) { return; } memberMap.SetSerializer(childSerializer.WithChildSerializer(serializerConfig.WithRepresentation(toType))); } }
public SubObjectDirtyTrackerTemplate(object aggregate, BsonMemberMap map) { _map = map; var currentSubObjectValue = aggregate == null ? null : _map.Getter(aggregate); _originalValue = _map.GetSerializer().ToBsonValue(currentSubObjectValue); _trackerTemplates = GetDirtyTrackerTemplates(_map.MemberType, currentSubObjectValue); }
public void Apply(BsonMemberMap memberMap) { if (memberMap.MemberType.IsEnum) { var serializer = memberMap.GetSerializer(); var camelCaseValueSerializer = new CamelCaseValueSerializer(serializer); memberMap.SetSerializer(camelCaseValueSerializer); } }
public void Apply(BsonMemberMap memberMap) { if (memberMap.ClassMap.ClassType.Name == memberMap.MemberType.Name) { return; } Debug.WriteLine(memberMap.ClassMap.ClassType.Name + "." + memberMap.MemberName); memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); }
private void SerializeMember(BsonSerializationContext context, TClass document, BsonMemberMap memberMap) { IBsonWriter bsonWriter = context.Writer; object value = memberMap.Getter(document); if (memberMap.ShouldSerialize(document, value)) { bsonWriter.WriteName(memberMap.ElementName); memberMap.GetSerializer().Serialize(context, value); } }
public void Apply(BsonMemberMap memberMap) { memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); //if (memberMap.GetType().IsGenericParameter) //{ // memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); //} //else //{ // memberMap.SetSerializer(memberMap.GetSerializer()); //} }
public void Apply(BsonMemberMap memberMap) { var type = memberMap.MemberType; if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(Dictionary <,>) || type.GetGenericTypeDefinition() == typeof(IDictionary <,>)) && type.GetGenericArguments().FirstOrDefault() != typeof(string)) { memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); } }
// public methods /// <inheritdoc/> public void Apply(BsonMemberMap memberMap) { var guidSerializer = memberMap.GetSerializer() as GuidSerializer; if (guidSerializer == null) { throw new InvalidOperationException("[BsonGuidRepresentationAttribute] can only be used when the serializer is a GuidSerializer."); } var reconfiguredGuidSerializer = guidSerializer.WithGuidRepresentation(_guidRepresentation); memberMap.SetSerializer(reconfiguredGuidSerializer); }
/// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { if (memberMap.MemberType.IsEnum) { var serializer = memberMap.GetSerializer(); var representationConfigurableSerializer = serializer as IRepresentationConfigurable; if (representationConfigurableSerializer != null) { var reconfiguredSerializer = representationConfigurableSerializer.WithRepresentation(_representation); memberMap.SetSerializer(reconfiguredSerializer); } } }
/// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { if (memberMap.MemberType.IsEnum) { var serializer = memberMap.GetSerializer(); var representationConfigurableSerializer = serializer as IRepresentationConfigurable; if (representationConfigurableSerializer != null) { var reconfiguredSerializer = representationConfigurableSerializer.WithRepresentation(_representation); memberMap.SetSerializer(reconfiguredSerializer); } } }
public void Apply(BsonMemberMap memberMap) { if (memberMap.MemberType == typeof(Guid)) { var serializer = memberMap.GetSerializer(); var representationConfigurableSerializer = serializer as IRepresentationConfigurable; if (representationConfigurableSerializer != null) { var reconfiguredSerializer = representationConfigurableSerializer.WithRepresentation(BsonType.String); memberMap.SetSerializer(reconfiguredSerializer); } } }
public void Apply(BsonMemberMap memberMap) { Type memberType = memberMap.MemberType; if (memberType.GetTypeInfo() == typeof(Type) && memberMap.MemberName == "SagaDefinitionType") { if (!(memberMap.GetSerializer() is IRepresentationConfigurable serializer)) { return; } IBsonSerializer serializer1 = serializer.WithRepresentation(this._representation); memberMap.SetSerializer(serializer1); } }
protected static BsonType GetBsonType(object value, BsonMemberMap memberMap) { BsonType keyBsonType; if (value == null) { keyBsonType = BsonType.Null; } else { var propertyInfo = memberMap.GetSerializer().GetType().GetProperty("Representation"); if (propertyInfo != null) { keyBsonType = (BsonType)propertyInfo.GetValue(memberMap.GetSerializer()); } else { keyBsonType = BsonType.Array; } } return(keyBsonType); }
private void SerializeMember(BsonWriter bsonWriter, object obj, BsonMemberMap memberMap) { object objA = memberMap.Getter(obj); if (objA == null && memberMap.IgnoreIfNull || (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && object.Equals(objA, memberMap.DefaultValue) || !memberMap.ShouldSerializeMethod(obj))) { return; } bsonWriter.WriteName(memberMap.ElementName); Type memberType = memberMap.MemberType; Type actualType = objA == null ? memberType : objA.GetType(); if (IsRelation(memberMap)) { ValidateVirtualRelation(memberMap); } memberMap.GetSerializer(actualType).Serialize(bsonWriter, memberType, objA, memberMap.SerializationOptions); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public virtual void Apply(BsonMemberMap memberMap) { var memberSerializer = memberMap.GetSerializer(memberMap.MemberType); var memberSerializationOptions = memberMap.SerializationOptions; if (memberSerializationOptions == null) { var memberDefaultSerializationOptions = memberSerializer.GetDefaultSerializationOptions(); if (memberDefaultSerializationOptions == null) { var message = string.Format( "A serialization options attribute of type {0} cannot be used when the serializer is of type {1}.", BsonUtils.GetFriendlyTypeName(this.GetType()), BsonUtils.GetFriendlyTypeName(memberSerializer.GetType())); throw new NotSupportedException(message); } memberSerializationOptions = memberDefaultSerializationOptions.Clone(); memberMap.SetSerializationOptions(memberSerializationOptions); } memberSerializationOptions.ApplyAttribute(memberSerializer, this); }
private object SerializeValue(object value, BsonMemberMap memberMap) { const string tmpField = "tmp"; var type = value.GetType(); var serializer = memberMap.GetSerializer(type); var document = new BsonDocument(); using (var writer = BsonWriter.Create(document)) { // serialize the value inside a document using the provided serializer writer.WriteStartDocument(); writer.WriteName(tmpField); serializer.Serialize(writer, type, value, memberMap.SerializationOptions); writer.WriteEndDocument(); } // extract the serialized value from the document return(document[tmpField]); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public virtual void Apply(BsonMemberMap memberMap) { var memberSerializer = memberMap.GetSerializer(memberMap.MemberType); var memberSerializationOptions = memberMap.SerializationOptions; if (memberSerializationOptions == null) { var memberDefaultSerializationOptions = memberSerializer.GetDefaultSerializationOptions(); if (memberDefaultSerializationOptions == null) { var message = string.Format( "A serialization options attribute of type {0} cannot be used when the serializer is of type {1}.", BsonUtils.GetFriendlyTypeName(this.GetType()), BsonUtils.GetFriendlyTypeName(memberSerializer.GetType())); throw new NotSupportedException(message); } memberSerializationOptions = memberDefaultSerializationOptions.Clone(); memberMap.SetSerializationOptions(memberSerializationOptions); } memberSerializationOptions.ApplyAttribute(memberSerializer, this); }
/// <summary> /// Applies a modification to the member map. /// </summary> /// The member map. public void Apply(BsonMemberMap memberMap) { var memberTypeInfo = memberMap.MemberType; if (memberTypeInfo == typeof(Guid)) { var declaringTypeAssembly = memberMap.ClassMap.ClassType.AssemblyQualifiedName; var asmName = declaringTypeAssembly; if (_protectedAssemblies.Any(a => a.FullName.Equals(asmName, StringComparison.OrdinalIgnoreCase))) { return; } var serializer = memberMap.GetSerializer(); if (serializer is IRepresentationConfigurable representationConfigurableSerializer) { var representation = BsonType.String; var reconfiguredSerializer = representationConfigurableSerializer.WithRepresentation(representation); memberMap.SetSerializer(reconfiguredSerializer); } } }
private ResourceType GetPropertyResourceType(BsonMemberMap memberMap) { var serializer = memberMap.GetSerializer(memberMap.MemberType); return(GetNonEntityResourceType(memberMap.MemberType, serializer)); }
public void Apply(BsonMemberMap memberMap) { memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer(),Array.Empty<IBsonSerializer>())); }
public void Apply(BsonMemberMap memberMap) { memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); }
private BsonValue GetBsonValue(object aggregate) { return(_memberMap.GetSerializer().ToBsonValue(_memberMap.Getter(aggregate))); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public virtual void Apply(BsonMemberMap memberMap) { var serializer = memberMap.GetSerializer(); var reconfiguredSerializer = Apply(serializer); memberMap.SetSerializer(reconfiguredSerializer); }
public void Apply(BsonMemberMap memberMap) { Console.WriteLine(memberMap.ClassMap.ClassType); memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); }