示例#1
0
        /// <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;
            }
        }
示例#2
0
        /// <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;
            }
        }