Beispiel #1
0
        /// <summary>
        /// Creates and adds a new member to this enum type.
        /// </summary>
        /// <param name="name">Name of the member.</param>
        /// <param name="value">Value of the member.</param>
        /// <returns>Created member.</returns>
        public EdmEnumMember AddMember(string name, IEdmPrimitiveValue value)
        {
            EdmEnumMember member = new EdmEnumMember(this, name, value);

            this.AddMember(member);
            return(member);
        }
        public ODataJsonLightReaderEnumIntegrationTests()
        {
            EdmModel tmpModel = new EdmModel();

            // enum without flags
            var enumType = new EdmEnumType("NS", "Color");
            var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1));
            enumType.AddMember(red);
            enumType.AddMember("Green", new EdmIntegerConstant(2));
            enumType.AddMember("Blue", new EdmIntegerConstant(3));
            tmpModel.AddElement(enumType);

            // enum with flags
            var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));
            tmpModel.AddElement(enumFlagsType);

            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            EdmStructuralProperty floatId = new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetSingle(false));
            this.entityType.AddKeys(floatId);
            this.entityType.AddProperty(floatId);
            var enumTypeReference = new EdmEnumTypeReference(enumType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference));
            var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference));

            // enum in complex type
            EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType");
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference));
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false)));
            tmpModel.AddElement(myComplexType);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true)));

            // enum in derived complex type
            EdmComplexType myDerivedComplexType = new EdmComplexType("NS", "MyDerivedComplexType", myComplexType, false);
            myDerivedComplexType.AddProperty(new EdmStructuralProperty(myDerivedComplexType, "MyDerivedColorFlags", new EdmEnumTypeReference(enumFlagsType, false)));
            tmpModel.AddElement(myDerivedComplexType);
            
            // enum in collection type
            EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType)));

            tmpModel.AddElement(this.entityType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub");
            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
            defaultContainer.AddEntitySet(this.entitySet.Name, this.entityType);
            tmpModel.AddElement(defaultContainer);

            this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", tmpModel);
        }
        public ODataAtomWriterEnumIntegrationTests()
        {
            this.userModel = new EdmModel();

            var enumType = new EdmEnumType("NS", "Color");
            var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1));
            enumType.AddMember(red);
            enumType.AddMember("Green", new EdmIntegerConstant(2));
            enumType.AddMember("Blue", new EdmIntegerConstant(3));

            // enum with flags
            var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));

            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            this.entityType.AddKeys(new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetDouble(false)));
            var enumTypeReference = new EdmEnumTypeReference(enumType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference));

            // add enum with flags
            var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference));

            // enum in complex type
            EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType");
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference));
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false)));
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true)));

            // enum in collection type
            EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType)));

            this.userModel.AddElement(this.entityType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");
            this.userModel.AddElement(defaultContainer);

            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
        }
        public EnumFilterFunctionalTests()
        {
            // set up the edm model etc
            this.userModel = new EdmModel();

            var enumType = new EdmEnumType("NS", "Color", EdmPrimitiveTypeKind.Int32, false);
            var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1));
            enumType.AddMember(red);
            enumType.AddMember("Green", new EdmIntegerConstant(2));
            enumType.AddMember("Blue", new EdmIntegerConstant(3));
            enumType.AddMember("White", new EdmIntegerConstant(-10));

            // add to model
            this.userModel.AddElement(enumType);

            // add enum property
            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            var enumTypeReference = new EdmEnumTypeReference(enumType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference));

            // enum with flags
            var enumFlagsType = new EdmEnumType("NS", "ColorFlags", EdmPrimitiveTypeKind.Int64, true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1L));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2L));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4L));
            enumFlagsType.AddMember("GreenRed", new EdmIntegerConstant(3L));

            // add to model
            this.userModel.AddElement(enumFlagsType);

            // add enum with flags
            var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference));

            this.userModel.AddElement(this.entityType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");
            this.userModel.AddElement(defaultContainer);

            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
            defaultContainer.AddElement(this.entitySet);
        }
        private void CreateEnumTypeBody(EdmEnumType type, EnumTypeConfiguration config)
        {
            Contract.Assert(type != null);
            Contract.Assert(config != null);

            foreach (EnumMemberConfiguration member in config.Members)
            {
                // EdmIntegerConstant can only support a value of long type.
                long value;
                try
                {
                    value = Convert.ToInt64(member.MemberInfo, CultureInfo.InvariantCulture);
                }
                catch
                {
                    throw Error.Argument("value", SRResources.EnumValueCannotBeLong, Enum.GetName(member.MemberInfo.GetType(), member.MemberInfo));
                }

                EdmEnumMember edmMember = new EdmEnumMember(type, member.Name,
                    new EdmIntegerConstant(value));
                type.AddMember(edmMember);
                _members[member.MemberInfo] = edmMember;
            }
        }
        private IEdmEnumMember ConvertToStockMember(IEdmEnumMember edmMember, IEdmModel edmModel, EdmModel stockModel)
        {
            var stockMemberDeclaringType = stockModel.FindType(GetFullName(edmMember.DeclaringType)) as IEdmEnumType;

            var stockMember = new EdmEnumMember(
                                        stockMemberDeclaringType,
                                        edmMember.Name,
                                        edmMember.Value
                                    );
            ((EdmEnumType)stockMemberDeclaringType).AddMember(stockMember);

            // TODO: Documentation
            this.SetImmediateAnnotations(edmMember, stockMember, edmModel, stockModel);

            return stockMember;
        }
        public void EdmEnumMemberReferenceExpression()
        {
            var et = new EdmEnumType("NS", "Spicy");
            var em = new EdmEnumMember(et, "Hot", new EdmIntegerConstant(5));
            var e = new EdmEnumMemberReferenceExpression(em);
            Assert.AreEqual(EdmExpressionKind.EnumMemberReference, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual("Hot", e.ReferencedEnumMember.Name, "e.ReferencedEnumMember");
            Assert.IsFalse(e.IsBad(), "e good");

            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmEnumMemberReferenceExpression(null));

            var ee = new MutableEdmEnumMemberReferenceExpression();
            Assert.IsNull(ee.ReferencedEnumMember, "e.ReferencedEntitySet");
            Assert.IsTrue(ee.IsBad(), "Expression is bad.");
            Assert.AreEqual(1, ee.Errors().Count(), "Expression has errors");
        }
Beispiel #8
0
 /// <summary>
 /// Creates and adds a new member to this enum type.
 /// </summary>
 /// <param name="name">Name of the member.</param>
 /// <param name="value">Value of the member.</param>
 /// <returns>Created member.</returns>
 public EdmEnumMember AddMember(string name, IEdmPrimitiveValue value)
 {
     EdmEnumMember member = new EdmEnumMember(this, name, value);
     this.AddMember(member);
     return member;
 }