当前位置: 首页>>代码示例>>C#>>正文


C# IEdmTypeReference.AsEnum方法代码示例

本文整理汇总了C#中IEdmTypeReference.AsEnum方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.AsEnum方法的具体用法?C# IEdmTypeReference.AsEnum怎么用?C# IEdmTypeReference.AsEnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEdmTypeReference的用法示例。


在下文中一共展示了IEdmTypeReference.AsEnum方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertValue

        internal static object ConvertValue(
            object odataValue,
            string parameterName,
            Type expectedReturnType,
            IEdmTypeReference propertyType,
            IEdmModel model,
            HttpRequestMessage request,
            IServiceProvider serviceProvider)
        {
            var readContext = new ODataDeserializerContext
            {
                Model = model,
                Request = request
            };

            // Enum logic can be removed after RestierEnumDeserializer extends ODataEnumDeserializer
            var deserializerProvider = serviceProvider.GetService<ODataDeserializerProvider>();
            var enumValue = odataValue as ODataEnumValue;
            if (enumValue != null)
            {
                ODataEdmTypeDeserializer deserializer
                    = deserializerProvider.GetEdmTypeDeserializer(propertyType.AsEnum());
                return deserializer.ReadInline(enumValue, propertyType, readContext);
            }

            var returnValue = ODataModelBinderConverter.Convert(
                odataValue, propertyType, expectedReturnType, parameterName, readContext, serviceProvider);

            if (!propertyType.IsCollection())
            {
                return returnValue;
            }

            return ConvertCollectionType(returnValue, expectedReturnType);
        }
开发者ID:chinadragon0515,项目名称:RESTier,代码行数:35,代码来源:DeserializationHelpers.cs

示例2: CreateODataValue

        /// <inheritdoc/>
        public sealed override ODataValue CreateODataValue(object graph, IEdmTypeReference expectedType, ODataSerializerContext writeContext)
        {
            if (!expectedType.IsEnum())
            {
                throw Error.InvalidOperation(SRResources.CannotWriteType, typeof(ODataEnumSerializer).Name, expectedType.FullName());
            }

            ODataEnumValue value = CreateODataEnumValue(graph, expectedType.AsEnum(), writeContext);
            if (value == null)
            {
                return new ODataNullValue();
            }

            return value;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:16,代码来源:ODataEnumSerializer.cs

示例3: CreateEdmTypeSerializer

        public override ODataSerializer CreateEdmTypeSerializer(IEdmTypeReference edmType)
        {
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }

            switch (edmType.TypeKind())
            {
                case EdmTypeKind.Primitive:
                    return new ODataPrimitiveSerializer(edmType.AsPrimitive());

                case EdmTypeKind.Collection:
                    IEdmCollectionTypeReference collectionType = edmType.AsCollection();
                    if (collectionType.ElementType().IsEntity())
                    {
                        return new ODataFeedSerializer(collectionType, this);
                    }
                    else
                    {
                        return new ODataCollectionSerializer(collectionType, this);
                    }

                case EdmTypeKind.Complex:
                    return new ODataComplexTypeSerializer(edmType.AsComplex(), this);

                case EdmTypeKind.Entity:
                    return new ODataEntityTypeSerializer(edmType.AsEntity(), this);

                case EdmTypeKind.Enum:
                    return new ODataEnumSerializer(edmType.AsEnum(), this);

                default:
                    throw Error.InvalidOperation(SRResources.TypeCannotBeSerialized, edmType.ToTraceString(), typeof(ODataMediaTypeFormatter).Name);
            }
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:36,代码来源:DefaultODataSerializerProvider.cs

示例4: ConvertEnumValue

        private static object ConvertEnumValue(ODataEnumValue enumValue, ref IEdmTypeReference propertyType,
            ODataDeserializerProvider deserializerProvider, ODataDeserializerContext readContext)
        {
            IEdmEnumTypeReference edmEnumType;
            if (propertyType == null)
            {
                // dynamic enum property
                Contract.Assert(!String.IsNullOrEmpty(enumValue.TypeName),
                    "ODataLib should have verified that dynamic enum value has a type name since we provided metadata.");
                IEdmModel model = readContext.Model;
                IEdmType edmType = model.FindType(enumValue.TypeName);
                Contract.Assert(edmType.TypeKind == EdmTypeKind.Enum, "ODataLib should have verified that enum value has a enum resource type.");
                edmEnumType = new EdmEnumTypeReference(edmType as IEdmEnumType, isNullable: true);
                propertyType = edmEnumType;
            }
            else
            {
                edmEnumType = propertyType.AsEnum();
            }

            ODataEdmTypeDeserializer deserializer = deserializerProvider.GetEdmTypeDeserializer(edmEnumType);
            return deserializer.ReadInline(enumValue, propertyType, readContext);
        }
开发者ID:joshcomley,项目名称:WebApi,代码行数:23,代码来源:DeserializationHelpers.cs

示例5: ConvertToTaupoDataType

        private DataType ConvertToTaupoDataType(IEdmTypeReference edmTypeReference)
        {
            EdmTypeKind kind = edmTypeReference.TypeKind();

            if (kind == EdmTypeKind.Collection)
            {
                var elementEdmTypeReference = edmTypeReference.AsCollection().ElementType();
                return DataTypes.CollectionType
                                 .WithElementDataType(this.ConvertToTaupoDataType(elementEdmTypeReference))
                                 .Nullable(edmTypeReference.IsNullable);
            }
            else if (kind == EdmTypeKind.Complex)
            {
                var complexEdmTypeDefinition = edmTypeReference.AsComplex().ComplexDefinition();
                return DataTypes.ComplexType
                                .WithName(complexEdmTypeDefinition.Namespace, complexEdmTypeDefinition.Name)
                                .Nullable(edmTypeReference.IsNullable);
            }
            else if (kind == EdmTypeKind.Entity)
            {
                var entityEdmTypeDefinition = edmTypeReference.AsEntity().EntityDefinition();
                return DataTypes.EntityType
                                .WithName(entityEdmTypeDefinition.Namespace, entityEdmTypeDefinition.Name)
                                .Nullable(edmTypeReference.IsNullable);
            }
            else if (kind == EdmTypeKind.EntityReference)
            {
                var entityEdmTypeDefinition = edmTypeReference.AsEntityReference().EntityType();
                return DataTypes.ReferenceType
                                .WithEntityType(new EntityTypeReference(entityEdmTypeDefinition.Namespace, entityEdmTypeDefinition.Name))
                                .Nullable(edmTypeReference.IsNullable);
            }
            else if (kind == EdmTypeKind.Primitive)
            {
                return EdmToTaupoPrimitiveDataTypeConverter.ConvertToTaupoPrimitiveDataType(edmTypeReference.AsPrimitive());
            }
            else if (kind == EdmTypeKind.Enum)
            {
                var enumTypeDefinition = edmTypeReference.AsEnum().EnumDefinition();
                return DataTypes.EnumType.WithName(enumTypeDefinition.Namespace, enumTypeDefinition.Name);
            }

            throw new TaupoInvalidOperationException("unexpected Edm Type Kind: " + kind);
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:44,代码来源:EdmToTaupoModelConverter.cs


注:本文中的IEdmTypeReference.AsEnum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。