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


C# IEdmModel.GetAnnotationValue方法代码示例

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


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

示例1: GetCanReflectOnInstanceTypeProperty

        /// <summary>
        /// Checks whether reflection over the property is allowed or not.
        /// </summary>
        /// <param name="property">The property to check.</param>
        /// <param name="model">The model containing annotations.</param>
        /// <returns>true if reflection over the property is allowed; otherwise false.</returns>
        public static bool GetCanReflectOnInstanceTypeProperty(this IEdmProperty property, IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(property, "property");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            ODataQueryEdmPropertyAnnotation annotation = model.GetAnnotationValue<ODataQueryEdmPropertyAnnotation>(property);
            return annotation == null ? false : annotation.CanReflectOnProperty;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:14,代码来源:ODataQueryUtils.cs

示例2: GetPropertyInfoTypeAnnotation

        /// <summary>
        /// Gets the property info annotation for the specified type or creates a new one if it doesn't exist.
        /// </summary>
        /// <param name="structuredType">The type to get the annotation for.</param>
        /// <param name="model">The model containing annotations.</param>
        /// <returns>The property info annotation.</returns>
        internal static PropertyInfoTypeAnnotation GetPropertyInfoTypeAnnotation(IEdmStructuredType structuredType, IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(structuredType != null, "structuredType != null");
            Debug.Assert(model != null, "model != null");

            PropertyInfoTypeAnnotation propertyInfoTypeAnnotation = model.GetAnnotationValue<PropertyInfoTypeAnnotation>(structuredType);
            if (propertyInfoTypeAnnotation == null)
            {
                propertyInfoTypeAnnotation = new PropertyInfoTypeAnnotation();
                model.SetAnnotationValue(structuredType, propertyInfoTypeAnnotation);
            }

            return propertyInfoTypeAnnotation;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:21,代码来源:PropertyInfoTypeAnnotation.cs

示例3: SetCanReflectOnInstanceTypeProperty

        /// <summary>
        /// Sets whether reflection over the property is allowed or not.
        /// </summary>
        /// <param name="property">The property to check.</param>
        /// <param name="model">The model containing annotations.</param>
        /// <param name="canReflect">true if reflection over the property is allowed; otherwise false.</param>
        public static void SetCanReflectOnInstanceTypeProperty(this IEdmProperty property, IEdmModel model, bool canReflect)
        {
            ExceptionUtils.CheckArgumentNotNull(property, "property");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            ODataQueryEdmPropertyAnnotation annotation = model.GetAnnotationValue<ODataQueryEdmPropertyAnnotation>(property);
            if (annotation == null)
            {
                if (canReflect)
                {
                    annotation = new ODataQueryEdmPropertyAnnotation
                    {
                        CanReflectOnProperty = true
                    };
                    model.SetAnnotationValue(property, annotation);
                }
            }
            else
            {
                annotation.CanReflectOnProperty = canReflect;
            }
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:28,代码来源:ODataQueryUtils.cs

示例4: GetInstanceType

        /// <summary>
        /// Returns the instance type for the specified <paramref name="typeReference"/> or null if none exists.
        /// </summary>
        /// <param name="typeReference">The type reference to get the instance type for.</param>
        /// <param name="model">The model containing annotations.</param>
        /// <returns>The instance type for the <paramref name="typeReference"/> or null if no instance type exists.</returns>
        /// <remarks>All primitive type references are guaranteed to have an instance type.</remarks>
        public static Type GetInstanceType(this IEdmTypeReference typeReference, IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(typeReference, "typeReference");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            if (typeReference.TypeKind() == EdmTypeKind.Primitive)
            {
                IEdmPrimitiveTypeReference primitiveTypeReference = typeReference.AsPrimitive();

                return EdmLibraryExtensions.GetPrimitiveClrType(primitiveTypeReference);
            }

            ODataQueryEdmTypeAnnotation annotation = model.GetAnnotationValue<ODataQueryEdmTypeAnnotation>(typeReference.Definition);
            return annotation == null ? null : annotation.InstanceType;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:22,代码来源:ODataQueryUtils.cs

示例5: GetClrPropertyName

        public static string GetClrPropertyName(IEdmProperty edmProperty, IEdmModel edmModel)
        {
            if (edmProperty == null)
            {
                throw Error.ArgumentNull("edmProperty");
            }

            if (edmModel == null)
            {
                throw Error.ArgumentNull("edmModel");
            }

            string propertyName = edmProperty.Name;
            ClrPropertyInfoAnnotation annotation = edmModel.GetAnnotationValue<ClrPropertyInfoAnnotation>(edmProperty);
            if (annotation != null)
            {
                PropertyInfo propertyInfo = annotation.ClrPropertyInfo;
                if (propertyInfo != null)
                {
                    propertyName = propertyInfo.Name;
                }
            }

            return propertyName;
        }
开发者ID:BarclayII,项目名称:WebApi,代码行数:25,代码来源:EdmLibHelpers.cs

示例6: GetClrType

        public static Type GetClrType(IEdmType edmType, IEdmModel edmModel, IAssembliesResolver assembliesResolver)
        {
            IEdmSchemaType edmSchemaType = edmType as IEdmSchemaType;

            Contract.Assert(edmSchemaType != null);

            ClrTypeAnnotation annotation = edmModel.GetAnnotationValue<ClrTypeAnnotation>(edmSchemaType);
            if (annotation != null)
            {
                return annotation.ClrType;
            }

            string typeName = edmSchemaType.FullName();
            IEnumerable<Type> matchingTypes = GetMatchingTypes(typeName, assembliesResolver);

            if (matchingTypes.Count() > 1)
            {
                throw Error.Argument("edmTypeReference", SRResources.MultipleMatchingClrTypesForEdmType,
                    typeName, String.Join(",", matchingTypes.Select(type => type.AssemblyQualifiedName)));
            }

            edmModel.SetAnnotationValue<ClrTypeAnnotation>(edmSchemaType, new ClrTypeAnnotation(matchingTypes.SingleOrDefault()));

            return matchingTypes.SingleOrDefault();
        }
开发者ID:BarclayII,项目名称:WebApi,代码行数:25,代码来源:EdmLibHelpers.cs

示例7: GetClrType

        public static Type GetClrType(IEdmType edmType, IEdmModel edmModel, IAssembliesResolver assembliesResolver)
        {
            Contract.Requires(edmType is IEdmSchemaType);
            Contract.Requires(edmModel != null);
            Contract.Requires(assembliesResolver != null);

            var edmSchemaType = (IEdmSchemaType) edmType;

            var annotation = edmModel.GetAnnotationValue<ClrTypeAnnotation>(edmSchemaType);
            if (annotation != null)
            {
                return annotation.ClrType;
            }

            var typeName = edmSchemaType.FullName();
            var matchingTypes = GetMatchingTypes(typeName, assembliesResolver);

            var matchingTypesList = matchingTypes as IList<Type> ?? matchingTypes.ToList();
            if (matchingTypesList.Count > 1)
            {
                throw new Exception("Multiple Matching ClrTypes For EdmType");
            }

            edmModel.SetAnnotationValue(edmSchemaType, new ClrTypeAnnotation(matchingTypesList.SingleOrDefault()));

            return matchingTypesList.SingleOrDefault();
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:27,代码来源:EdmLibHelpers.cs

示例8: GetClrType

        public static Type GetClrType(IEdmTypeReference edmTypeReference, IEdmModel edmModel, IAssembliesResolver assembliesResolver)
        {
            if (edmTypeReference == null)
            {
                throw Error.ArgumentNull("edmTypeReference");
            }

            Type primitiveClrType = _builtInTypesMapping
                .Where(kvp => edmTypeReference.Definition.IsEquivalentTo(kvp.Value) && (!edmTypeReference.IsNullable || IsNullable(kvp.Key)))
                .Select(kvp => kvp.Key)
                .FirstOrDefault();

            if (primitiveClrType != null)
            {
                return primitiveClrType;
            }
            else
            {
                ClrTypeAnnotation annotation = edmModel.GetAnnotationValue<ClrTypeAnnotation>(edmTypeReference.Definition);
                if (annotation != null)
                {
                    return annotation.ClrType;
                }

                IEnumerable<Type> matchingTypes = GetMatchingTypes(edmTypeReference.FullName(), assembliesResolver);

                if (matchingTypes.Count() > 1)
                {
                    throw Error.Argument("edmTypeReference", SRResources.MultipleMatchingClrTypesForEdmType,
                        edmTypeReference.FullName(), String.Join(",", matchingTypes.Select(type => type.AssemblyQualifiedName)));
                }

                edmModel.SetAnnotationValue<ClrTypeAnnotation>(edmTypeReference.Definition, new ClrTypeAnnotation(matchingTypes.SingleOrDefault()));

                return matchingTypes.SingleOrDefault();
            }
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:37,代码来源:EdmLibHelpers.cs

示例9: IsSerializedAsElement

 /// <summary>
 /// Gets an annotation indicating if the value should be serialized as an element.
 /// </summary>
 /// <param name="value">Value the annotation is on.</param>
 /// <param name="model">Model containing the value.</param>
 /// <returns>Value indicating if the string should be serialized as an element.</returns>
 public static bool IsSerializedAsElement(this IEdmValue value, IEdmModel model)
 {
     EdmUtil.CheckArgumentNull(value, "value");
     EdmUtil.CheckArgumentNull(model, "model");
     return (model.GetAnnotationValue(value, EdmConstants.InternalUri, CsdlConstants.IsSerializedAsElementAnnotation) as bool?) ?? false;
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:12,代码来源:SerializationExtensionMethods.cs

示例10: GetSchemaNamespace

 /// <summary>
 /// Gets the schema an annotation should be serialized in.
 /// </summary>
 /// <param name="annotation">Reference to the calling annotation.</param>
 /// <param name="model">Model containing the annotation.</param>
 /// <returns>Name of the schema the annotation belongs to.</returns>
 public static string GetSchemaNamespace(this IEdmVocabularyAnnotation annotation, IEdmModel model)
 {
     EdmUtil.CheckArgumentNull(annotation, "annotation");
     EdmUtil.CheckArgumentNull(model, "model");
     return model.GetAnnotationValue<string>(annotation, EdmConstants.InternalUri, CsdlConstants.SchemaNamespaceAnnotation);
 }
开发者ID:larsenjo,项目名称:odata.net,代码行数:12,代码来源:SerializationExtensionMethods.cs

示例11: IsServiceOperation

        /// <summary>
        /// Method that checks whether a function import is a service operation.
        /// </summary>
        /// <param name="functionImport">The <see cref="IEdmFunctionImport"/> to check.</param>
        /// <param name="model">The <see cref="IEdmModel"/> containing annotations.</param>
        /// <returns>true if the <paramref name="functionImport"/> represents a service operation; otherwise false.</returns>
        /// <remarks>
        /// A <see cref="IEdmFunctionImport"/> is considered a service operation if it has the
        /// <see cref="ODataQueryEdmServiceOperationAnnotation"/> annotation.
        /// </remarks>
        private static bool IsServiceOperation(IEdmFunctionImport functionImport, IEdmModel model)
        {
            Debug.Assert(functionImport != null, "functionImport != null");
            Debug.Assert(model != null, "model != null");

            // Check whether an annotation on the function import that makes it a service operation exists
            ODataQueryEdmServiceOperationAnnotation serviceOperationAnnotation = model.GetAnnotationValue<ODataQueryEdmServiceOperationAnnotation>(functionImport);
            return serviceOperationAnnotation != null;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:19,代码来源:ODataQueryUtils.cs

示例12: SetCanReflectOnInstanceType

        /// <summary>
        /// Sets whether reflection over the instance type is allowed or not.
        /// </summary>
        /// <param name="type">The type to check.</param>
        /// <param name="model">Model containing annotations.</param>
        /// <param name="canReflect">true if reflection over the instance type is allowed; otherwise false.</param>
        public static void SetCanReflectOnInstanceType(this IEdmType type, IEdmModel model, bool canReflect)
        {
            ExceptionUtils.CheckArgumentNotNull(type, "type");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            if (type.TypeKind == EdmTypeKind.Primitive)
            {
                throw new ODataException(Strings.ODataQueryUtils_CannotSetMetadataAnnotationOnPrimitiveType);
            }

            ODataQueryEdmTypeAnnotation annotation = model.GetAnnotationValue<ODataQueryEdmTypeAnnotation>(type);
            if (annotation == null)
            {
                if (canReflect)
                {
                    annotation = new ODataQueryEdmTypeAnnotation { CanReflectOnInstanceType = true };
                    model.SetAnnotationValue(type, annotation);
                }
            }
            else
            {
                annotation.CanReflectOnInstanceType = canReflect;
            }
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:30,代码来源:ODataQueryUtils.cs

示例13: GetCanReflectOnInstanceType

        public static bool GetCanReflectOnInstanceType(this IEdmTypeReference typeReference, IEdmModel model)
        {
            ExceptionUtils.CheckArgumentNotNull(typeReference, "typeReference");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            if (typeReference.TypeKind() == EdmTypeKind.Primitive)
            {
                // we can reflect over all primitive types
                return true;
            }

            ODataQueryEdmTypeAnnotation annotation = model.GetAnnotationValue<ODataQueryEdmTypeAnnotation>(typeReference.Definition);
            return annotation == null ? false : annotation.CanReflectOnInstanceType;
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:14,代码来源:ODataQueryUtils.cs

示例14: SetInstanceType

        /// <summary>
        /// Sets the instance type for the specified <paramref name="type"/>; if null is specified an existing instance type will be removed.
        /// </summary>
        /// <param name="type">The type to get the instance type for.</param>
        /// <param name="model">Model containing annotations.</param>
        /// <param name="instanceType">The instance type for the <paramref name="type"/> or null to remove an existing instance type.</param>
        public static void SetInstanceType(this IEdmType type, IEdmModel model, Type instanceType)
        {
            ExceptionUtils.CheckArgumentNotNull(type, "type");
            ExceptionUtils.CheckArgumentNotNull(model, "model");

            if (type.TypeKind == EdmTypeKind.Primitive)
            {
                throw new ODataException(Strings.ODataQueryUtils_CannotSetMetadataAnnotationOnPrimitiveType);
            }

            ODataQueryEdmTypeAnnotation existingAnnotation = model.GetAnnotationValue<ODataQueryEdmTypeAnnotation>(type);
            if (existingAnnotation == null)
            {
                if (instanceType != null)
                {
                    ODataQueryEdmTypeAnnotation newAnnotation = new ODataQueryEdmTypeAnnotation
                    {
                        InstanceType = instanceType,
                    };

                    model.SetAnnotationValue(type, newAnnotation);
                }
            }
            else
            {
                existingAnnotation.InstanceType = instanceType;
            }
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:34,代码来源:ODataQueryUtils.cs

示例15: TranslateEdmTypeToClrType

            //-----------------------------------------------------------------------------------------------------------------------------------------------------
            private Type TranslateEdmTypeToClrType(IEdmModel model, IEdmType edmType)
            {
                var annotation = model.GetAnnotationValue<ClrTypeAnnotation>(edmType);

                if ( annotation != null )
                {
                    return annotation.ClrType;
                }

                var entityType = (edmType as IEdmEntityType);

                if ( entityType != null )
                {
                    return base.Context.Factory.FindDynamicType(new EdmEntityTypeKey(model, entityType));
                }

                var collectionType = (edmType as IEdmCollectionType);

                if ( collectionType != null )
                {
                    var elementClrType = TranslateEdmTypeToClrType(model, collectionType.ElementType.Definition);
                    return typeof (DataServiceCollection<>).MakeGenericType(elementClrType);
                }

                var primitiveType = (edmType as IEdmPrimitiveType);

                if ( primitiveType != null )
                {
                    return s_BuiltInTypesMapping[primitiveType];
                }

                throw new Exception("Could not determine CLR type for EDM type: " + edmType.FullTypeName() + " {" + edmType.GetType().Name + "}");
            }
开发者ID:votrongdao,项目名称:NWheels,代码行数:34,代码来源:ODataClientEntityFactory.cs


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