MongoDB.Bson.Serialization.Conventions.AttributeConventionPack.AttributeConvention.ThrowForDuplicateMemberMapAttributes C# (CSharp) Method

ThrowForDuplicateMemberMapAttributes() private method

private ThrowForDuplicateMemberMapAttributes ( BsonClassMap classMap ) : void
classMap BsonClassMap
return void
            private void ThrowForDuplicateMemberMapAttributes(BsonClassMap classMap)
            {
                var nonDuplicatesAlreadySeen = new List<Type>();
                foreach (var memberMap in classMap.DeclaredMemberMaps)
                {
                    var attributes = (IBsonMemberMapAttribute[])memberMap.MemberInfo.GetCustomAttributes(typeof(IBsonMemberMapAttribute), false);
#pragma warning disable 618 // obsoleted by IBsonMemberMapModifier
                    var legacyAttributes = (IBsonMemberMapModifier[])memberMap.MemberInfo.GetCustomAttributes(typeof(IBsonMemberMapModifier), false);
                    // combine them only if the modifier isn't already in the attributes list...
                    var attributeTypes = attributes
                        .Select(x => x.GetType())
                        .Union(legacyAttributes.Where(x => !(x is IBsonMemberMapAttribute)).Select(x => x.GetType()));
#pragma warning restore 618
                    foreach (var attributeType in attributeTypes)
                    {
                        if (nonDuplicatesAlreadySeen.Contains(attributeType))
                        {
                            var message = string.Format("Attributes of type {0} can only be applied to a single member.", attributeType);
                            throw new DuplicateBsonMemberMapAttributeException(message);
                        }

                        if (!AllowsDuplicate(attributeType))
                        {
                            nonDuplicatesAlreadySeen.Add(attributeType);
                        }
                    }
                }
            }
        }