// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { if (memberMap.MemberType == _type) { memberMap.SetSerializationOptions(_serializationOptions); } }
/// <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) { memberMap.SetSerializationOptions(new RepresentationSerializationOptions(_representation)); } }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { if (memberMap.MemberType == _type) { memberMap.SetDefaultValue(_defaultValue); } }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { if (!string.IsNullOrEmpty(_elementName)) { memberMap.SetElementName(_elementName); } memberMap.SetOrder(_order); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetDefaultValue(_defaultValue); if (_serializeDefaultValueWasSet) { memberMap.SetIgnoreIfNull(false); memberMap.SetIgnoreIfDefault(!_serializeDefaultValue); } }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetOrder(_order); if (_idGenerator != null) { var idGenerator = (IIdGenerator)Activator.CreateInstance(_idGenerator); // public default constructor required memberMap.SetIdGenerator(idGenerator); } memberMap.ClassMap.SetIdMember(memberMap); }
/// <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 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> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { var memberType = memberMap.MemberType; var memberTypeInfo = memberType.GetTypeInfo(); if (memberTypeInfo == typeof(Guid)) { if (memberMap.GetSerializer() is IRepresentationConfigurable representationConfigurableSerializer) { var bsonSerializer = representationConfigurableSerializer.WithRepresentation(Representation); memberMap.SetSerializer(bsonSerializer); } return; } if (!IsNullableGuid(memberType)) { return; } var serializer = memberMap.GetSerializer(); if (!(serializer is IChildSerializerConfigurable childSerializerConfigurableSerializer)) { return; } var childSerializer = childSerializerConfigurableSerializer.ChildSerializer; if (!(childSerializer is IRepresentationConfigurable representationConfigurableChildSerializer)) { return; } var reconfiguredChildSerializer = representationConfigurableChildSerializer.WithRepresentation(Representation); var reconfiguredSerializer = childSerializerConfigurableSerializer.WithChildSerializer(reconfiguredChildSerializer); memberMap.SetSerializer(reconfiguredSerializer); }
public void Apply(BsonClassMap classMap) { var properties = classMap.ClassType .GetTypeInfo() .GetProperties(_bindingFlags) .Where(p => p.PropertyType != typeof(Type)) .ToList(); var mappingProperties = properties .Where(p => IsReadOnlyProperty(classMap, p) || IsInitOnlyProperty(p)) .ToList(); foreach (PropertyInfo property in mappingProperties) { BsonMemberMap member = classMap.MapMember(property); if (IsNullableProperty(property)) { member.SetDefaultValue((object?)null); } } if (!classMap.ClassType.IsAbstract) { foreach (ConstructorInfo constructor in classMap.ClassType.GetConstructors( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)) { List <PropertyInfo> matchProperties = GetMatchingProperties(constructor, properties); if (matchProperties.Any()) { BsonCreatorMap creatorMap = classMap.MapConstructor(constructor); creatorMap.SetArguments(matchProperties); } } } }
/// <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); } } }
protected virtual decimal readAmount(IBsonReader reader) { BsonMemberMap amountMap = _map.GetMemberMap(m => m.Amount); reader.ReadName(amountMap.ElementName); decimal amount; // support old numeric representations BsonType type = reader.GetCurrentBsonType(); switch (type) { case BsonType.Double: { double amountRead = reader.ReadDouble(); amount = Convert.ToDecimal(amountRead); break; } case BsonType.Decimal128: { Decimal128 amountRead = reader.ReadDecimal128(); amount = Decimal128.ToDecimal(amountRead); break; } case BsonType.String: { string amountRead = reader.ReadString(); amount = decimal.Parse(amountRead, CultureInfo.InvariantCulture); break; } default: var message = $"Cannot convert a {type} to a Decimal."; throw new NotSupportedException(message); } return(amount); }
public FindResult Find(Expression expression) { if (expression.NodeType == ExpressionType.Parameter) { return(null); } _fieldParts = new Stack <string>(); _isBlocked = false; _bsonMemberMap = null; Visit(expression); var fieldName = string.Join(".", _fieldParts.ToArray()); if (_isBlocked) { return(null); } return(new FindResult { FieldName = fieldName, MemberMap = _bsonMemberMap }); }
/// <summary> /// Applies the specified member map convention. /// </summary> /// <param name="memberMap">The member map convention.</param> public void Apply(BsonMemberMap memberMap) { Func <Type, IBsonSerializer> converter = t => { if (t == typeof(DateTime)) { return(new DateTimeSerializer(DateTimeKind.Local)); } else if (t == typeof(DateTime?)) { return(new NullableSerializer <DateTime>(new DateTimeSerializer(DateTimeKind.Local))); } return(null); }; IBsonSerializer serializer = null; switch (memberMap.MemberInfo.MemberType) { case MemberTypes.Property: PropertyInfo propertyInfo = (PropertyInfo)memberMap.MemberInfo; serializer = converter(propertyInfo.PropertyType); break; case MemberTypes.Field: FieldInfo fieldInfo = (FieldInfo)memberMap.MemberInfo; serializer = converter(fieldInfo.FieldType); break; default: break; } if (serializer != null) { memberMap.SetSerializer(serializer); } }
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); }
public void Apply(BsonMemberMap memberMap) { IBsonSerializer serializer = null; switch (memberMap.MemberInfo.MemberType) { case MemberTypes.Property: var propertyInfo = (PropertyInfo)memberMap.MemberInfo; serializer = GetBsonSerializer(propertyInfo.PropertyType); break; case MemberTypes.Field: var fieldInfo = (FieldInfo)memberMap.MemberInfo; serializer = GetBsonSerializer(fieldInfo.FieldType); break; default: break; } if (serializer != null) { memberMap.SetSerializer(serializer); } }
public void Apply(BsonMemberMap memberMap) { IsRun = true; RunCount++; RunTicks = _stopwatch.ElapsedTicks; }
public void Apply(BsonMemberMap memberMap) { var value = _convention.GetSerializationOptions(memberMap.MemberInfo); memberMap.SetSerializationOptions(value); }
public MemberDirtyTracker(object aggregate, BsonMemberMap memberMap, BsonValue originalValue) { _aggregate = aggregate; _memberMap = memberMap; OriginalValue = originalValue; }
public void Apply(BsonMemberMap memberMap) { var value = _convention.IgnoreIfNull(memberMap.MemberInfo); memberMap.SetIgnoreIfNull(value); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { _action(memberMap); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { var serializer = CreateSerializer(memberMap.MemberType); memberMap.SetSerializer(serializer); }
// 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 methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.Reset(); }
private void DeserializeMember( BsonReader bsonReader, object obj, BsonMemberMap memberMap ) { var nominalType = memberMap.MemberType; Type actualType; if (bsonReader.CurrentBsonType == BsonType.Null) { actualType = nominalType; } else { var discriminatorConvention = BsonDefaultSerializer.LookupDiscriminatorConvention(nominalType); actualType = discriminatorConvention.GetActualType(bsonReader, nominalType); // returns nominalType if no discriminator found } var serializer = memberMap.GetSerializerForActualType(actualType); var value = serializer.Deserialize(bsonReader, nominalType, actualType, memberMap.SerializationOptions); memberMap.Setter(obj, value); }
private void SerializeMember( BsonWriter bsonWriter, object obj, BsonMemberMap memberMap ) { var value = memberMap.Getter(obj); if (value == null && memberMap.IgnoreIfNull) { return; // don't serialize null value } if (memberMap.HasDefaultValue && !memberMap.SerializeDefaultValue && value.Equals(memberMap.DefaultValue)) { return; // don't serialize default value } var nominalType = memberMap.MemberType; var actualType = (value == null) ? nominalType : value.GetType(); var serializer = memberMap.GetSerializerForActualType(actualType); var elementName = memberMap.ElementName; bsonWriter.WriteName(elementName); serializer.Serialize(bsonWriter, nominalType, value, memberMap.SerializationOptions); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetIgnoreIfNull(false); memberMap.SetIgnoreIfDefault(_value); }
/// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetIgnoreIfDefault(_ignoreIfDefault); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.ClassMap.SetExtraElementsMember(memberMap); }
public void Apply(BsonMemberMap memberMap) { var attributes = memberMap.MemberInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false).Cast<IBsonMemberMapAttribute>(); var groupings = attributes.GroupBy(a => (a is BsonSerializerAttribute) ? 1 : 2); foreach (var grouping in groupings.OrderBy(g => g.Key)) { foreach (var attribute in grouping) { attribute.Apply(memberMap); } } }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { string name = memberMap.MemberName; name = GetElementName(name); memberMap.SetElementName(name); }
private static void ShouldSerializeIfNotDefault(BsonMemberMap memberMap, string defaultString) => memberMap.SetShouldSerializeMethod(@object => !string.Equals(defaultString, memberMap.Getter(@object) as string));
public void Apply(BsonMemberMap memberMap) { memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer(),Array.Empty<IBsonSerializer>())); }
public void Apply(BsonMemberMap memberMap) { MapDateTime(memberMap); MapDateTimeOffset(memberMap); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetIsRequired(true); }
/// <summary>应用约定</summary> public void Apply(BsonMemberMap memberMap) { memberMap.SetElementName(memberMap.MemberName.ToLower()); }
public void Apply(BsonMemberMap memberMap) { var name = _convention.GetElementName(memberMap.MemberInfo); memberMap.SetElementName(name); }
private ResourceType GetPropertyResourceType(BsonMemberMap memberMap) { var serializer = memberMap.GetSerializer(memberMap.MemberType); return(GetNonEntityResourceType(memberMap.MemberType, serializer)); }
public void Apply(BsonMemberMap memberMap) { var value = _convention.SerializeDefaultValue(memberMap.MemberInfo); memberMap.SetIgnoreIfDefault(value); }
// public methods /// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetElementName(memberMap.MemberName); }
public void Apply(BsonMemberMap memberMap) { string elementName = memberMap.MemberName.Substring(0, 1).ToLower() + memberMap.MemberName.Substring(1); memberMap.SetElementName(elementName); }
/// <inheritdoc /> public void Apply(BsonMemberMap memberMap) { memberMap.UpdateIncrementally(); }
private void SerializeExtraElements( BsonWriter bsonWriter, object obj, BsonMemberMap extraElementsMemberMap ) { var extraElements = (BsonDocument) extraElementsMemberMap.Getter(obj); if (extraElements != null) { foreach (var element in extraElements) { element.WriteTo(bsonWriter); } } }
protected virtual void writeAmount(Money value, IBsonWriter writer) { BsonMemberMap amountMap = _map.GetMemberMap(m => m.Amount); writer.WriteDouble(amountMap.ElementName, Convert.ToDouble(value.Amount)); }
private static UpdateDefinition <TImplementation> _SetValue(BsonMemberMap memberMap, UpdateDefinition <TImplementation> update, object newValue) { var safeVal = _GetSafeValue(memberMap, newValue); return(update.Set(memberMap.ElementName, safeVal)); }
/// <summary> /// Applies a modification to the member map. /// </summary> /// <param name="memberMap">The member map.</param> public void Apply(BsonMemberMap memberMap) { memberMap.SetIgnoreIfNull(_ignoreIfNull); }
public void Apply(BsonMemberMap memberMap) { memberMap.SetSerializer(ConfigureSerializer(memberMap.GetSerializer())); }
private void DeserializeExtraElement( BsonReader bsonReader, object obj, string elementName, BsonMemberMap extraElementsMemberMap ) { var extraElements = (BsonDocument) extraElementsMemberMap.Getter(obj); if (extraElements == null) { extraElements = new BsonDocument(); extraElementsMemberMap.Setter(obj, extraElements); } var value = BsonValue.ReadFrom(bsonReader); extraElements[elementName] = value; }
public void Apply(BsonMemberMap memberMap) { var defaultValue = _target.GetDefaultValue(memberMap.MemberInfo); if (defaultValue != null) { memberMap.ApplyDefaultValue(defaultValue); } }
public void Apply(BsonMemberMap memberMap) { foreach (IBsonMemberMapAttribute attribute in memberMap.MemberInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false)) { attribute.Apply(memberMap); } #pragma warning disable 618 // obsoleted by IBsonMemberMapModifier foreach (IBsonMemberMapModifier attribute in memberMap.MemberInfo.GetCustomAttributes(typeof(IBsonMemberMapModifier), false)) { // only apply this if it wasn't already applied if (!(attribute is IBsonMemberMapAttribute)) { attribute.Apply(memberMap); } } #pragma warning restore 618 }
public void Apply(BsonMemberMap mm) { mm.SetIgnoreIfDefault(true); }