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


C# IEdmTypeReference.AsEntity方法代码示例

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


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

示例1: CreateEdmTypeSerializer

        /// <summary>
        /// Creates a new instance of the <see cref="ODataEntrySerializer"/> for the given edm type.
        /// </summary>
        /// <param name="edmType">The <see cref="IEdmTypeReference"/>.</param>
        /// <returns>The constructed <see cref="ODataEntrySerializer"/>.</returns>
        public virtual ODataEntrySerializer 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);

                default:
                    return null;
            }
        }
开发者ID:Rhombulus,项目名称:aspnetwebstack,代码行数:38,代码来源:DefaultODataSerializerProvider.cs

示例2: 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);

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

示例3: CreateDeserializer

        protected override ODataEntryDeserializer CreateDeserializer(IEdmTypeReference edmType)
        {
            if (edmType != null)
            {
                switch (edmType.TypeKind())
                {
                    case EdmTypeKind.Entity:
                        return new ODataEntityDeserializer(edmType.AsEntity(), this);

                    case EdmTypeKind.Primitive:
                        return new ODataPrimitiveDeserializer(edmType.AsPrimitive());

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

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

            return null;
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:30,代码来源:DefaultODataDeserializerProvider.cs

示例4: CreateDeserializer

        protected override ODataEntryDeserializer CreateDeserializer(IEdmTypeReference edmType)
        {
            if (edmType != null)
            {
                switch (edmType.TypeKind())
                {
                    case EdmTypeKind.Entity:
                        return new ODataEntityDeserializer(edmType.AsEntity(), this);

                    case EdmTypeKind.Primitive:
                        return new ODataRawValueDeserializer(edmType.AsPrimitive());

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

            return null;
        }
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:19,代码来源:DefaultODataDeserializerProvider.cs

示例5: ReadInline

        /// <inheritdoc />
        public sealed override object ReadInline(object item, IEdmTypeReference edmType, ODataDeserializerContext readContext)
        {
            if (item == null)
            {
                throw Error.ArgumentNull("item");
            }
            if (edmType == null)
            {
                throw Error.ArgumentNull("edmType");
            }
            if (!edmType.IsEntity())
            {
                throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Entity);
            }

            ODataEntryWithNavigationLinks entryWrapper = item as ODataEntryWithNavigationLinks;
            if (entryWrapper == null)
            {
                throw Error.Argument("item", SRResources.ArgumentMustBeOfType, typeof(ODataEntry).Name);
            }

            // Recursion guard to avoid stack overflows
            RuntimeHelpers.EnsureSufficientExecutionStack();

            return ReadEntry(entryWrapper, edmType.AsEntity(), readContext);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:27,代码来源:ODataEntityDeserializer.cs

示例6: WriteDynamicTypeEntry

        private void WriteDynamicTypeEntry(object graph, ODataWriter writer, IEdmTypeReference expectedType,
            ODataSerializerContext writeContext)
        {
            var navigationProperties = new Dictionary<IEdmTypeReference, object>();
            var entityType = expectedType.Definition as EdmEntityType;
            var entry = new ODataEntry()
            {
                TypeName = expectedType.FullName(),
                Properties = CreateODataPropertiesFromDynamicType(entityType, graph, navigationProperties)
            };

            entry.IsTransient = true;
            writer.WriteStart(entry);
            foreach (IEdmTypeReference type in navigationProperties.Keys)
            {
                var entityContext = new EntityInstanceContext(writeContext, expectedType.AsEntity(), graph);
                var navigationProperty = entityType.NavigationProperties().FirstOrDefault(p => p.Type.Equals(type));
                var navigationLink = CreateNavigationLink(navigationProperty, entityContext);
                if (navigationLink != null)
                {
                    writer.WriteStart(navigationLink);
                    WriteDynamicTypeEntry(navigationProperties[type], writer, type, writeContext);
                    writer.WriteEnd();
                }
            }

            writer.WriteEnd();
        }
开发者ID:chinadragon0515,项目名称:WebApi,代码行数:28,代码来源:ODataEntityTypeSerializer.cs

示例7: ConvertEntity

            internal static object ConvertEntity(ODataMessageReader oDataMessageReader, IEdmTypeReference edmTypeReference,
                ODataDeserializerContext readContext)
            {
                IEdmEntityTypeReference entityType = edmTypeReference.AsEntity();

                EdmEntitySet tempEntitySet = new EdmEntitySet(readContext.Model.EntityContainer, "temp",
                    entityType.EntityDefinition());

                ODataReader entryReader = oDataMessageReader.CreateODataEntryReader(tempEntitySet,
                    entityType.EntityDefinition());

                object item = ODataEntityDeserializer.ReadEntryOrFeed(entryReader);

                ODataEntryWithNavigationLinks topLevelEntry = item as ODataEntryWithNavigationLinks;
                Contract.Assert(topLevelEntry != null);

                ODataEntityDeserializer entityDeserializer =
                    (ODataEntityDeserializer)DeserializerProvider.GetEdmTypeDeserializer(entityType);
                object entity = entityDeserializer.ReadInline(topLevelEntry, entityType, readContext);
                return CovertEntityId(entity, topLevelEntry.Entry, entityType, readContext);
            }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:21,代码来源:ODataModelBinderProvider.cs

示例8: ResolveAndValidateTargetTypeStrictValidationDisabled

        /// <summary>
        /// Resolves the payload type versus the expected type and validates that such combination is allowed when the strict validation is disabled.
        /// </summary>
        /// <param name="expectedTypeKind">The expected type kind for the value.</param>
        /// <param name="expectedTypeReference">The expected type reference, or null if no expected type is available.</param>
        /// <param name="payloadType">The payload type, or null if the payload type was not specified, or it didn't resolve against the model.</param>
        /// <returns>The target type reference to use for parsing the value.</returns>
        private static IEdmTypeReference ResolveAndValidateTargetTypeStrictValidationDisabled(
            EdmTypeKind expectedTypeKind,
            IEdmTypeReference expectedTypeReference,
            IEdmType payloadType)
        {
            // Lax validation logic
            switch (expectedTypeKind)
            {
                case EdmTypeKind.Complex:
                    // if the expectedTypeKind is different from the payloadType.TypeKind the types are not related 
                    // in any way. In that case we will just use the expected type because we are in lax mode. 
                    if (payloadType != null && expectedTypeKind == payloadType.TypeKind)
                    {
                        // Verify if it's a derived complex type, in all other cases simply use the expected type.
                        VerifyComplexType(expectedTypeReference, payloadType, /* failIfNotRelated */ false);
                        if (EdmLibraryExtensions.IsAssignableFrom(expectedTypeReference.AsComplex().ComplexDefinition(), (IEdmComplexType)payloadType))
                        {
                            return payloadType.ToTypeReference(/*nullable*/ true);
                        }
                    }

                    break;
                case EdmTypeKind.Entity:
                    // if the expectedTypeKind is different from the payloadType.TypeKind the types are not related 
                    // in any way. In that case we will just use the expected type because we are in lax mode. 
                    if (payloadType != null && expectedTypeKind == payloadType.TypeKind)
                    {
                        // If the type is assignable (equal or derived) we will use the payload type, since we want to allow derived entities
                        if (EdmLibraryExtensions.IsAssignableFrom(expectedTypeReference.AsEntity().EntityDefinition(), (IEdmEntityType)payloadType))
                        {
                            IEdmTypeReference payloadTypeReference = payloadType.ToTypeReference(/*nullable*/ true);
                            return payloadTypeReference;
                        }
                    }

                    break;
                case EdmTypeKind.Collection:
                    // if the expectedTypeKind is different from the payloadType.TypeKind the types are not related 
                    // in any way. In that case we will just use the expected type because we are in lax mode. 
                    if (payloadType != null && expectedTypeKind == payloadType.TypeKind)
                    {
                        VerifyCollectionComplexItemType(expectedTypeReference, payloadType);
                    }

                    break;
                case EdmTypeKind.Enum: // enum: no validation

                    break;
                case EdmTypeKind.TypeDefinition: // type definition: no validation

                    break;
                default:
                    throw new ODataException(Strings.General_InternalError(InternalErrorCodes.ReaderValidationUtils_ResolveAndValidateTypeName_Strict_TypeKind));
            }

            // Either there's no payload type, in which case use the expected one, or the payload one and the expected one are equal.
            return expectedTypeReference;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:65,代码来源:ReaderValidationUtils.cs

示例9: GetPropertyValueAsText

        /// <summary>
        /// Given a target segment the method returns the text value of the property mapped to that segment to be used in EPM.
        /// </summary>
        /// <param name="targetSegment">The target segment to read the value for.</param>
        /// <param name="epmValueCache">EPM value cache to use to get property values, or a primitive value</param>
        /// <param name="typeReference">The type of the entry or collection item.</param>
        /// <returns>The test representation of the value, or the method throws if the text representation was not possible to obtain.</returns>
        private string GetPropertyValueAsText(
            EpmTargetPathSegment targetSegment,
            object epmValueCache,
            IEdmTypeReference typeReference)
        {
            Debug.Assert(targetSegment != null, "targetSegment != null");
            Debug.Assert(targetSegment.HasContent, "The target segment to read property for must have content.");
            Debug.Assert(targetSegment.EpmInfo != null, "The EPM info must be available on the target segment to read its property.");
            Debug.Assert(epmValueCache != null, "epmValueCache != null");
            Debug.Assert(typeReference != null, "typeReference != null");

            object propertyValue;
            EntryPropertiesValueCache entryPropertiesValueCache = epmValueCache as EntryPropertiesValueCache;

            if (entryPropertiesValueCache != null)
            {
                propertyValue = this.ReadEntryPropertyValue(
                    targetSegment.EpmInfo,
                    entryPropertiesValueCache,
                    typeReference.AsEntity());
            }
            else
            { 
                propertyValue = epmValueCache;
                ValidationUtils.ValidateIsExpectedPrimitiveType(propertyValue, typeReference);
            }

            return EpmWriterUtils.GetPropertyValueAsText(propertyValue);
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:36,代码来源:EpmSyndicationWriter.cs

示例10: 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

示例11: ResolveAndValidateTargetTypeStrictValidationDisabled

        private static IEdmTypeReference ResolveAndValidateTargetTypeStrictValidationDisabled(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, IEdmType payloadType, string payloadTypeName, out SerializationTypeNameAnnotation serializationTypeNameAnnotation)
        {
            switch (expectedTypeKind)
            {
                case EdmTypeKind.Entity:
                {
                    if (((payloadType == null) || (expectedTypeKind != payloadType.TypeKind)) || !expectedTypeReference.AsEntity().EntityDefinition().IsAssignableFrom(((IEdmEntityType) payloadType)))
                    {
                        break;
                    }
                    IEdmTypeReference targetTypeReference = payloadType.ToTypeReference(true);
                    serializationTypeNameAnnotation = CreateSerializationTypeNameAnnotation(payloadTypeName, targetTypeReference);
                    return targetTypeReference;
                }
                case EdmTypeKind.Complex:
                    if ((payloadType != null) && (expectedTypeKind == payloadType.TypeKind))
                    {
                        VerifyComplexType(expectedTypeReference, payloadType, false);
                    }
                    break;

                case EdmTypeKind.Collection:
                    if ((payloadType != null) && (expectedTypeKind == payloadType.TypeKind))
                    {
                        VerifyCollectionComplexItemType(expectedTypeReference, payloadType);
                    }
                    break;

                default:
                    throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.ReaderValidationUtils_ResolveAndValidateTypeName_Strict_TypeKind));
            }
            serializationTypeNameAnnotation = CreateSerializationTypeNameAnnotation(payloadTypeName, expectedTypeReference);
            return expectedTypeReference;
        }
开发者ID:nickchal,项目名称:pash,代码行数:34,代码来源:ReaderValidationUtils.cs

示例12: GetPropertyValueAsText

 private string GetPropertyValueAsText(EpmTargetPathSegment targetSegment, object epmValueCache, IEdmTypeReference typeReference)
 {
     object obj2;
     EntryPropertiesValueCache cache = epmValueCache as EntryPropertiesValueCache;
     if (cache != null)
     {
         obj2 = base.ReadEntryPropertyValue(targetSegment.EpmInfo, cache, typeReference.AsEntity());
     }
     else
     {
         obj2 = epmValueCache;
         ValidationUtils.ValidateIsExpectedPrimitiveType(obj2, typeReference);
     }
     return EpmWriterUtils.GetPropertyValueAsText(obj2);
 }
开发者ID:nickchal,项目名称:pash,代码行数:15,代码来源:EpmSyndicationWriter.cs


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