// public methods
        /// <summary>
        /// Applies a modification to the creator map.
        /// </summary>
        /// <param name="creatorMap">The creator map.</param>
        public void Apply(BsonCreatorMap creatorMap)
        {
            if (creatorMap.Arguments == null)
            {
                if (creatorMap.MemberInfo != null)
                {
                    var parameters = GetParameters(creatorMap.MemberInfo);
                    if (parameters != null)
                    {
                        var arguments = new List<MemberInfo>();

                        foreach (var parameter in parameters)
                        {
                            var argument = FindMatchingArgument(creatorMap.ClassMap.ClassType, parameter);
                            if (argument == null)
                            {
                            }
                            arguments.Add(argument);
                        }

                        creatorMap.SetArguments(arguments);
                    }
                }
            }
        }
 // public methods
 /// <summary>
 /// Applies a modification to the creator map.
 /// </summary>
 /// <param name="creatorMap">The creator map.</param>
 public void Apply(BsonCreatorMap creatorMap)
 {
     if (_argumentNames != null)
     {
         creatorMap.SetArguments(_argumentNames);
     }
 }
        // public methods
        /// <summary>
        /// Applies a modification to the creator map.
        /// </summary>
        /// <param name="creatorMap">The creator map.</param>
        public void Apply(BsonCreatorMap creatorMap)
        {
            if (creatorMap.Arguments == null)
            {
                if (creatorMap.MemberInfo != null)
                {
                    var parameters = GetParameters(creatorMap.MemberInfo);
                    if (parameters != null)
                    {
                        var arguments = new List <MemberInfo>();

                        foreach (var parameter in parameters)
                        {
                            var argument = FindMatchingArgument(creatorMap.ClassMap.ClassType, parameter);
                            if (argument == null)
                            {
                                var message = string.Format("Unable to find a matching member to provide the value for parameter '{0}'.", parameter.Name);
                                throw new BsonException(message);
                            }
                            arguments.Add(argument);
                        }

                        creatorMap.SetArguments(arguments);
                    }
                }
            }
        }
        // public methods
        /// <summary>
        /// Applies a modification to the creator map.
        /// </summary>
        /// <param name="creatorMap">The creator map.</param>
        public void Apply(BsonCreatorMap creatorMap)
        {
            if (creatorMap.Arguments == null)
            {
                if (creatorMap.MemberInfo != null)
                {
                    var parameters = GetParameters(creatorMap.MemberInfo);
                    if (parameters != null)
                    {
                        var arguments = new List <MemberInfo>();

                        foreach (var parameter in parameters)
                        {
                            var argument = FindMatchingArgument(creatorMap.ClassMap.ClassType, parameter);
                            if (argument == null)
                            {
                                return;
                            }
                            arguments.Add(argument);
                        }

                        creatorMap.SetArguments(arguments);
                    }
                }
            }
        }
Example #5
0
 // public methods
 /// <summary>
 /// Applies a modification to the creator map.
 /// </summary>
 /// <param name="creatorMap">The creator map.</param>
 public void Apply(BsonCreatorMap creatorMap)
 {
     if (_argumentNames != null)
     {
         creatorMap.SetArguments(_argumentNames);
     }
 }
        // public methods
        /// <summary>
        /// Applies a modification to the creator map.
        /// </summary>
        /// <param name="creatorMap">The creator map.</param>
        public void Apply(BsonCreatorMap creatorMap)
        {
            if (creatorMap.Arguments == null)
            {
                if (creatorMap.MemberInfo != null)
                {
                    var parameters = GetParameters(creatorMap.MemberInfo);
                    if (parameters != null)
                    {
                        var arguments = new List<MemberInfo>();

                        foreach (var parameter in parameters)
                        {
                            var argument = FindMatchingArgument(creatorMap.ClassMap.ClassType, parameter);
                            if (argument == null)
                            {
                                var message = string.Format("Unable to find a matching member to provide the value for parameter '{0}'.", parameter.Name);
                            }
                            arguments.Add(argument);
                        }

                        creatorMap.SetArguments(arguments);
                    }
                }
            }
        }
 public void Apply(BsonCreatorMap creatorMap)
 {
     if (creatorMap.MemberInfo != null)
     {
         foreach (var attribute in creatorMap.MemberInfo.GetCustomAttributes(inherit: false).OfType <IBsonCreatorMapAttribute>())
         {
             attribute.Apply(creatorMap);
         }
     }
 }
 public void Apply(BsonCreatorMap creatorMap)
 {
     if (creatorMap.MemberInfo != null)
     {
         foreach (IBsonCreatorMapAttribute attribute in creatorMap.MemberInfo.GetCustomAttributes(typeof(IBsonCreatorMapAttribute), false))
         {
             attribute.Apply(creatorMap);
         }
     }
 }
 public void Apply(BsonCreatorMap creatorMap)
 {
     if (creatorMap.MemberInfo != null)
     {
         foreach (var attribute in creatorMap.MemberInfo.GetCustomAttributes(inherit: false).OfType<IBsonCreatorMapAttribute>())
         {
             attribute.Apply(creatorMap);
         }
     }
 }
 public void Apply(BsonCreatorMap creatorMap)
 {
     if (creatorMap.MemberInfo != null)
     {
         foreach (IBsonCreatorMapAttribute attribute in creatorMap.MemberInfo.GetCustomAttributes(typeof(IBsonCreatorMapAttribute), false))
         {
             attribute.Apply(creatorMap);
         }
     }
 }
            public void Apply(BsonCreatorMap creatorMap)
            {
                if (creatorMap.MemberInfo != null)
                {
#if NETCORE50 || NETSTANDARD1_5 || NETSTANDARD1_6
                    foreach (IBsonCreatorMapAttribute attribute in creatorMap.MemberInfo.CustomAttributes.Where(c => c.AttributeType is IBsonCreatorMapAttribute))
#else
                    foreach (IBsonCreatorMapAttribute attribute in creatorMap.MemberInfo.GetCustomAttributes(typeof(IBsonCreatorMapAttribute), false))
#endif
                    {
                        attribute.Apply(creatorMap);
                    }
                }
            }
Example #12
0
        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);
                    }
                }
            }
        }