/// <summary>
        /// Adds an enum member to this enum type.
        /// </summary>
        /// <param name="member">The member being added.</param>
        /// <returns>The <see cref="EnumMemberConfiguration"/> so that the member can be configured further.</returns>
        public EnumMemberConfiguration AddMember(Enum member)
        {
            if (member == null)
            {
                throw Error.ArgumentNull("member");
            }

            if (member.GetType() != ClrType)
            {
                throw Error.Argument("member", SRResources.PropertyDoesNotBelongToType, member.ToString(), ClrType.FullName);
            }

            // Remove from the ignored members
            if (RemovedMembers.Contains(member))
            {
                RemovedMembers.Remove(member);
            }

            EnumMemberConfiguration memberConfiguration;

            if (ExplicitMembers.ContainsKey(member))
            {
                memberConfiguration = ExplicitMembers[member];
            }
            else
            {
                memberConfiguration     = new EnumMemberConfiguration(member, this);
                ExplicitMembers[member] = memberConfiguration;
            }

            return(memberConfiguration);
        }
        /// <inheritdoc />
        public override EnumTypeConfiguration AddEnumType(Type type)
        {
            if (type == null)
            {
                throw Error.ArgumentNull("type");
            }

            if (!type.IsEnum)
            {
                throw Error.Argument("type", SRResources.TypeCannotBeEnum, type.FullName);
            }

            EnumTypeConfiguration enumTypeConfiguration = EnumTypes.SingleOrDefault(e => e.ClrType == type);

            if (enumTypeConfiguration == null)
            {
                enumTypeConfiguration = base.AddEnumType(type);

                foreach (object member in Enum.GetValues(type))
                {
                    bool addedExplicitly = enumTypeConfiguration.Members.Any(m => m.Name.Equals(member.ToString()));
                    EnumMemberConfiguration enumMemberConfiguration = enumTypeConfiguration.AddMember((Enum)member);
                    enumMemberConfiguration.AddedExplicitly = addedExplicitly;
                }
                ApplyEnumTypeConventions(enumTypeConfiguration);
            }

            return(enumTypeConfiguration);
        }
Esempio n. 3
0
        public void PassNullToEnumMemberConfigurationNameSetterShouldThrowException()
        {
            // Arrange
            Enum member  = Color.Red;
            var  builder = new ODataModelBuilder();

            builder.EnumType <Color>();
            EnumTypeConfiguration declaringType = builder.EnumTypes.Single();
            var enumMemberConfiguration         = new EnumMemberConfiguration(member, declaringType);

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => enumMemberConfiguration.Name = null,
                "value");
        }
        /// <summary>
        /// Adds an enum member to this enum type.
        /// </summary>
        /// <param name="member">The member being added.</param>
        /// <returns>The <see cref="EnumMemberConfiguration"/> so that the member can be configured further.</returns>
        public EnumMemberConfiguration AddMember(Enum member)
        {
            if (member == null)
            {
                throw Error.ArgumentNull("member");
            }

            if (member.GetType() != ClrType)
            {
                throw Error.Argument("member", SRResources.PropertyDoesNotBelongToType, member.ToString(), ClrType.FullName);
            }

            // Remove from the ignored members
            if (RemovedMembers.Contains(member))
            {
                RemovedMembers.Remove(member);
            }

            EnumMemberConfiguration memberConfiguration;
            if (ExplicitMembers.ContainsKey(member))
            {
                memberConfiguration = ExplicitMembers[member];
            }
            else
            {
                memberConfiguration = new EnumMemberConfiguration(member, this);
                ExplicitMembers[member] = memberConfiguration;
            }

            return memberConfiguration;
        }
Esempio n. 5
0
        public void PassNullToEnumMemberConfigurationNameSetterShouldThrowException()
        {
            // Arrange
            Enum member = Color.Red;
            var builder = new ODataModelBuilder();
            builder.EnumType<Color>();
            EnumTypeConfiguration declaringType = builder.EnumTypes.Single();
            var enumMemberConfiguration = new EnumMemberConfiguration(member, declaringType);

            // Act & Assert
            Assert.ThrowsArgumentNull(
                () => enumMemberConfiguration.Name = null,
                "value");
        }