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


C# IEdmModel.IsUserModel方法代码示例

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


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

示例1: ResolveAndValidateTypeName

        /// <summary>
        /// Validates a type name to ensure that it's not an empty string and resolves it against the provided <paramref name="model"/>.
        /// </summary>
        /// <param name="model">The model to use.</param>
        /// <param name="typeName">The type name to validate.</param>
        /// <param name="expectedTypeKind">The expected type kind for the given type name.</param>
        /// <returns>The type with the given name and kind if a user model was available, otherwise null.</returns>
        internal static IEdmType ResolveAndValidateTypeName(IEdmModel model, string typeName, EdmTypeKind expectedTypeKind)
        {
            Debug.Assert(model != null, "model != null");

            if (typeName == null)
            {
                // if we have metadata, the type name of an entry must not be null
                if (model.IsUserModel())
                {
                    throw new ODataException(Strings.WriterValidationUtils_MissingTypeNameWithMetadata);
                }

                return null;
            }

            if (typeName.Length == 0)
            {
                throw new ODataException(Strings.ValidationUtils_TypeNameMustNotBeEmpty);
            }

            if (!model.IsUserModel())
            {
                return null;
            }

            // If we do have metadata, lookup the type and translate it to a type.
            IEdmType resolvedType = MetadataUtils.ResolveTypeNameForWrite(model, typeName);
            if (resolvedType == null)
            {
                throw new ODataException(Strings.ValidationUtils_UnrecognizedTypeName(typeName));
            }

            ValidationUtils.ValidateTypeKind(resolvedType.TypeKind, expectedTypeKind, resolvedType.ODataFullName());
            return resolvedType;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:42,代码来源:TypeNameOracle.cs

示例2: ResolveAndValidateNonPrimitiveTargetType

 internal static IEdmTypeReference ResolveAndValidateNonPrimitiveTargetType(EdmTypeKind expectedTypeKind, IEdmTypeReference expectedTypeReference, EdmTypeKind payloadTypeKind, IEdmType payloadType, string payloadTypeName, IEdmModel model, ODataMessageReaderSettings messageReaderSettings, ODataVersion version, out SerializationTypeNameAnnotation serializationTypeNameAnnotation)
 {
     bool flag = (messageReaderSettings.ReaderBehavior.TypeResolver != null) && (payloadType != null);
     if (!flag)
     {
         ValidateTypeSupported(expectedTypeReference, version);
         if (model.IsUserModel() && ((expectedTypeReference == null) || !messageReaderSettings.DisableStrictMetadataValidation))
         {
             VerifyPayloadTypeDefined(payloadTypeName, payloadType);
         }
     }
     else
     {
         ValidateTypeSupported((payloadType == null) ? null : payloadType.ToTypeReference(true), version);
     }
     if ((payloadTypeKind != EdmTypeKind.None) && (!messageReaderSettings.DisableStrictMetadataValidation || (expectedTypeReference == null)))
     {
         ValidationUtils.ValidateTypeKind(payloadTypeKind, expectedTypeKind, payloadTypeName);
     }
     serializationTypeNameAnnotation = null;
     if (!model.IsUserModel())
     {
         return null;
     }
     if ((expectedTypeReference == null) || flag)
     {
         return ResolveAndValidateTargetTypeWithNoExpectedType(expectedTypeKind, payloadType, payloadTypeName, out serializationTypeNameAnnotation);
     }
     if (messageReaderSettings.DisableStrictMetadataValidation)
     {
         return ResolveAndValidateTargetTypeStrictValidationDisabled(expectedTypeKind, expectedTypeReference, payloadType, payloadTypeName, out serializationTypeNameAnnotation);
     }
     return ResolveAndValidateTargetTypeStrictValidationEnabled(expectedTypeKind, expectedTypeReference, payloadType, payloadTypeName, out serializationTypeNameAnnotation);
 }
开发者ID:nickchal,项目名称:pash,代码行数:34,代码来源:ReaderValidationUtils.cs

示例3: ODataJsonLightContextUriParser

        /// <summary>
        /// Initializes a new instance of the <see cref="ODataJsonLightContextUriParseResult"/> class.
        /// </summary>
        /// <param name="model">The model to use when resolving the target of the URI.</param>
        /// <param name="contextUriFromPayload">The context URI read from the payload.</param>
        private ODataJsonLightContextUriParser(IEdmModel model, Uri contextUriFromPayload)
        {
            Debug.Assert(model != null, "model != null");

            if (!model.IsUserModel())
            {
                throw new ODataException(ODataErrorStrings.ODataJsonLightContextUriParser_NoModel);
            }

            this.model = model;
            this.parseResult = new ODataJsonLightContextUriParseResult(contextUriFromPayload);
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:17,代码来源:ODataJsonLightContextUriParser.cs

示例4: ValidateEntityTypeName

 internal static IEdmEntityType ValidateEntityTypeName(IEdmModel model, string typeName)
 {
     if (typeName != null)
     {
         return ValidationUtils.ValidateEntityTypeName(model, typeName);
     }
     if (model.IsUserModel())
     {
         throw new ODataException(Microsoft.Data.OData.Strings.WriterValidationUtils_MissingTypeNameWithMetadata);
     }
     return null;
 }
开发者ID:nickchal,项目名称:pash,代码行数:12,代码来源:WriterValidationUtils.cs

示例5: ODataEntityPropertyMappingCache

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mappings">The EPM mappings to create the cache for.</param>
        /// <param name="model">The EDM model.</param>
        /// <param name="totalMappingCount">The total number of entity property mappings 
        /// for the entity type that this cache is created for (on the type itself and all its base types).</param>
        internal ODataEntityPropertyMappingCache(ODataEntityPropertyMappingCollection mappings, IEdmModel model, int totalMappingCount)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(model.IsUserModel(), "model.IsUserModel()");

            this.mappings = mappings;
            this.model = model;
            this.totalMappingCount = totalMappingCount;

            // Note that we new up everything here eagerly because we will only create the EPM annotation for types
            // for which we know for sure that they have EPM and thus we will need all of these anyway.
            this.mappingsForInheritedProperties = new List<EntityPropertyMappingAttribute>();
            this.mappingsForDeclaredProperties = mappings == null
                ? new List<EntityPropertyMappingAttribute>()
                : new List<EntityPropertyMappingAttribute>(mappings);
            this.epmTargetTree = new EpmTargetTree();
            this.epmSourceTree = new EpmSourceTree(this.epmTargetTree);
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:25,代码来源:ODataEntityPropertyMappingCache.cs

示例6: ValidateTypeName

        /// <summary>
        /// Validates a type name to ensure that it's not an empty string and resolves it against the provided <paramref name="model"/>.
        /// </summary>
        /// <param name="model">The model to use.</param>
        /// <param name="typeName">The type name to validate.</param>
        /// <returns>The type with the given name and kind if a user model was available, otherwise null.</returns>
        internal static IEdmType ValidateTypeName(IEdmModel model, string typeName)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(model != null, "model != null");
            Debug.Assert(typeName != null, "typeName != null");

            if (typeName.Length == 0)
            {
                throw new ODataException(Strings.ValidationUtils_TypeNameMustNotBeEmpty);
            }

            // If we do have metadata, lookup the type and translate it to a type.
            IEdmType type = MetadataUtils.ResolveTypeNameForWrite(model, typeName);
            if (model.IsUserModel() && type == null)
            {
                throw new ODataException(Strings.ValidationUtils_UnrecognizedTypeName(typeName));
            }

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

示例7: ResolveTypeName

 private static IEdmType ResolveTypeName(IEdmModel model, IEdmType expectedType, string typeName, Func<IEdmType, string, IEdmType> customTypeResolver, ODataVersion version, out EdmTypeKind typeKind)
 {
     IEdmType collectionType = null;
     EdmTypeKind kind;
     string str = (version >= ODataVersion.V3) ? EdmLibraryExtensions.GetCollectionItemTypeName(typeName) : null;
     if (str == null)
     {
         if ((customTypeResolver != null) && model.IsUserModel())
         {
             collectionType = customTypeResolver(expectedType, typeName);
             if (collectionType == null)
             {
                 throw new ODataException(Microsoft.Data.OData.Strings.MetadataUtils_ResolveTypeName(typeName));
             }
         }
         else
         {
             collectionType = model.FindType(typeName);
         }
         if (((version < ODataVersion.V3) && (collectionType != null)) && collectionType.IsSpatial())
         {
             collectionType = null;
         }
         typeKind = (collectionType == null) ? EdmTypeKind.None : collectionType.TypeKind;
         return collectionType;
     }
     typeKind = EdmTypeKind.Collection;
     IEdmType definition = null;
     if (((customTypeResolver != null) && (expectedType != null)) && (expectedType.TypeKind == EdmTypeKind.Collection))
     {
         definition = ((IEdmCollectionType) expectedType).ElementType.Definition;
     }
     IEdmType itemType = ResolveTypeName(model, definition, str, customTypeResolver, version, out kind);
     if (itemType != null)
     {
         collectionType = EdmLibraryExtensions.GetCollectionType(itemType);
     }
     return collectionType;
 }
开发者ID:nickchal,项目名称:pash,代码行数:39,代码来源:MetadataUtils.cs

示例8: ValidateValueTypeName

        /// <summary>
        /// Validates a type name to ensure that it's not an empty string.
        /// </summary>
        /// <param name="model">The model to use.</param>
        /// <param name="typeName">The type name to validate.</param>
        /// <param name="typeKind">The expected type kind for the given type name.</param>
        /// <param name="isOpenPropertyType">True if the type name belongs to an open property.</param>
        /// <returns>The type with the given name and kind if the model is a user model, otherwise null.</returns>
        internal static IEdmType ValidateValueTypeName(IEdmModel model, string typeName, EdmTypeKind typeKind, bool isOpenPropertyType)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(model != null, "model != null");
            Debug.Assert(typeKind != EdmTypeKind.Entity, "This method is only for value types.");

            if (typeName == null)
            {
                // if we have metadata the type name of an entry or a complex value of an open property must not be null
                if (model.IsUserModel() && isOpenPropertyType)
                {
                    throw new ODataException(Strings.WriterValidationUtils_MissingTypeNameWithMetadata);
                }

                return null;
            }

            return ValidationUtils.ValidateValueTypeName(model, typeName, typeKind);
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:27,代码来源:WriterValidationUtils.cs

示例9: ResolveAndValidateNonPrimitiveTargetType

        /// <summary>
        /// Resolves the payload type versus the expected type and validates that such combination is allowed.
        /// </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="payloadTypeKind">The payload type kind, this may be the one from the type itself, or one detected without resolving the type.</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>
        /// <param name="payloadTypeName">The payload type name, or null if no payload type was specified.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="messageReaderSettings">The message reader settings to use.</param>
        /// <returns>
        /// The target type reference to use for parsing the value.
        /// If there is no user specified model, this will return null.
        /// If there is a user specified model, this method never returns null.
        /// </returns>
        /// <remarks>
        /// This method cannot be used for primitive type resolution. Primitive type resolution is format dependent and format specific methods should be used instead.
        /// </remarks>
        internal static IEdmTypeReference ResolveAndValidateNonPrimitiveTargetType(
            EdmTypeKind expectedTypeKind,
            IEdmTypeReference expectedTypeReference,
            EdmTypeKind payloadTypeKind,
            IEdmType payloadType,
            string payloadTypeName,
            IEdmModel model,
            ODataMessageReaderSettings messageReaderSettings)
        {
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");
            Debug.Assert(
                expectedTypeKind == EdmTypeKind.Enum || expectedTypeKind == EdmTypeKind.Complex || expectedTypeKind == EdmTypeKind.Entity ||
                expectedTypeKind == EdmTypeKind.Collection || expectedTypeKind == EdmTypeKind.TypeDefinition,
                "The expected type kind must be one of Enum, Complex, Entity, Collection or TypeDefinition.");
            Debug.Assert(
                payloadTypeKind == EdmTypeKind.Complex || payloadTypeKind == EdmTypeKind.Entity ||
                payloadTypeKind == EdmTypeKind.Collection || payloadTypeKind == EdmTypeKind.None ||
                payloadTypeKind == EdmTypeKind.Primitive || payloadTypeKind == EdmTypeKind.Enum ||
                payloadTypeKind == EdmTypeKind.TypeDefinition,
                "The payload type kind must be one of None, Primitive, Enum, Complex, Entity, Collection or TypeDefinition.");
            Debug.Assert(
                expectedTypeReference == null || expectedTypeReference.TypeKind() == expectedTypeKind,
                "The expected type kind must match the expected type reference if that is available.");
            Debug.Assert(
                payloadType == null || payloadType.TypeKind == payloadTypeKind,
                "The payload type kind must match the payload type if that is available.");
            Debug.Assert(payloadType == null || payloadTypeName != null, "If we have a payload type, we must have its name as well.");

            bool useExpectedTypeOnlyForTypeResolution = messageReaderSettings.ReaderBehavior.TypeResolver != null && payloadType != null;
            if (!useExpectedTypeOnlyForTypeResolution)
            {
                ValidateTypeSupported(expectedTypeReference);

                // We should validate that the payload type resolved before anything else to produce reasonable error messages
                // Otherwise we might report errors which are somewhat confusing (like "Type '' is Complex but Collection was expected.").
                if (model.IsUserModel() && (expectedTypeReference == null || !messageReaderSettings.DisableStrictMetadataValidation))
                {
                    // When using a type resolver (i.e., useExpectedTypeOnlyForTypeResolution == true) then we don't have to
                    // call this method because the contract with the type resolver is to always resolve the type name and thus
                    // we will always get a defined type.
                    VerifyPayloadTypeDefined(payloadTypeName, payloadType);
                }
            }
            else
            {
                // Payload types are always nullable.
                ValidateTypeSupported(payloadType == null ? null : payloadType.ToTypeReference(/*nullable*/ true));
            }

            // In lax mode don't cross check kinds of types (we would just use the expected type) unless we expect
            // an open property of a specific kind (e.g. top level complex property for PUT requests)
            if (payloadTypeKind != EdmTypeKind.None && (!messageReaderSettings.DisableStrictMetadataValidation || expectedTypeReference == null))
            {
                // Make sure that the type kinds match.
                ValidationUtils.ValidateTypeKind(payloadTypeKind, expectedTypeKind, payloadTypeName);
            }

            if (!model.IsUserModel())
            {
                // If there's no model, it means we should not have the expected type either, and that there's no type to use,
                // no metadata validation to perform.
                Debug.Assert(expectedTypeReference == null, "If we don't have a model, we must not have expected type either.");
                return null;
            }

            if (expectedTypeReference == null || useExpectedTypeOnlyForTypeResolution)
            {
                Debug.Assert(payloadTypeName == null || payloadType != null, "The payload type must have resolved before we get here.");
                return ResolveAndValidateTargetTypeWithNoExpectedType(
                    expectedTypeKind,
                    payloadType);
            }

            if (messageReaderSettings.DisableStrictMetadataValidation)
            {
                return ResolveAndValidateTargetTypeStrictValidationDisabled(
                    expectedTypeKind,
                    expectedTypeReference,
                    payloadType);
            }

            Debug.Assert(payloadTypeName == null || payloadType != null, "The payload type must have resolved before we get here.");
//.........这里部分代码省略.........
开发者ID:rossjempson,项目名称:odata.net,代码行数:101,代码来源:ReaderValidationUtils.cs

示例10: ResolveTypeName

        /// <summary>
        /// Resolves the name of a primitive, complex, entity or collection type to the respective type.
        /// </summary>
        /// <param name="model">The model to use or null if no model is available.</param>
        /// <param name="expectedType">The expected type for the type name being resolved, or null if none is available.</param>
        /// <param name="typeName">The name of the type to resolve.</param>
        /// <param name="customTypeResolver">Custom type resolver to use, if null the model is used directly.</param>
        /// <param name="version">The version to use when resolving the type name.</param>
        /// <param name="typeKind">The type kind of the type, if it could be determined. This will be None if we couldn't tell. It might be filled
        /// even if the method returns null, for example for Collection types with item types which are not recognized.</param>
        /// <returns>The <see cref="IEdmType"/> representing the type specified by the <paramref name="typeName"/>;
        /// or null if no such type could be found.</returns>
        private static IEdmType ResolveTypeName(
            IEdmModel model,
            IEdmType expectedType,
            string typeName,
            Func<IEdmType, string, IEdmType> customTypeResolver,
            ODataVersion version,
            out EdmTypeKind typeKind)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(typeName != null, "typeName != null");
            IEdmType resolvedType = null;

            // Collection types should only be recognized in V3 and higher.
            string itemTypeName = version >= ODataVersion.V3 ? EdmLibraryExtensions.GetCollectionItemTypeName(typeName) : null;
            if (itemTypeName == null)
            {
                // Note: we require the type resolver or the model to also resolve
                //       primitive types.
                if (customTypeResolver != null && model.IsUserModel())
                {
                    resolvedType = customTypeResolver(expectedType, typeName);
                    if (resolvedType == null)
                    {
                        // If a type resolver is specified it must never return null.
                        throw new ODataException(Strings.MetadataUtils_ResolveTypeName(typeName));
                    }
                }
                else
                {
                    resolvedType = model.FindType(typeName);
                }

                // Spatial types are only recognized in V3 and higher.
                if (version < ODataVersion.V3 && resolvedType != null && resolvedType.IsSpatial())
                {
                    resolvedType = null;
                }

                typeKind = resolvedType == null ? EdmTypeKind.None : resolvedType.TypeKind;
            }
            else
            {
                // Collection
                typeKind = EdmTypeKind.Collection;
                EdmTypeKind itemTypeKind;

                IEdmType expectedItemType = null;
                if (customTypeResolver != null && expectedType != null && expectedType.TypeKind == EdmTypeKind.Collection)
                {
                    expectedItemType = ((IEdmCollectionType)expectedType).ElementType.Definition;
                }

                IEdmType itemType = ResolveTypeName(model, expectedItemType, itemTypeName, customTypeResolver, version, out itemTypeKind);
                if (itemType != null)
                {
                    resolvedType = EdmLibraryExtensions.GetCollectionType(itemType);
                }
            }

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

示例11: ShouldValidateComplexPropertyNullValue

        /// <summary>
        /// Null validation of complex properties will be skipped if edm version is less than v3 and data service version exists.
        /// In such cases, the provider decides what should be done if a null value is stored on a non-nullable complex property.
        /// </summary>
        /// <param name="model">The model containing the complex property.</param>
        /// <returns>True if complex property should be validated for null values.</returns>
        internal static bool ShouldValidateComplexPropertyNullValue(IEdmModel model)
        {
            DebugUtils.CheckNoExternalCallers();

            Debug.Assert(model != null, "For null validation model is required.");
            Debug.Assert(model.IsUserModel(), "For complex properties, the model should be user model.");

            Version edmVersion = model.GetEdmVersion();
            Version dataServiceVersion = model.GetDataServiceVersion();

            if (edmVersion != null && dataServiceVersion != null && edmVersion < ODataVersion.V3.ToDataServiceVersion())
            {
                return false;
            }

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

示例12: ResolveAndValidatePrimitiveTargetType

        /// <summary>
        /// Resolves the primitive payload type versus the expected type and validates that such combination is allowed.
        /// </summary>
        /// <param name="expectedTypeReference">The expected type reference, if any.</param>
        /// <param name="payloadTypeKind">The kind of the payload type, or None if the detection was not possible.</param>
        /// <param name="payloadType">The resolved payload type, or null if no payload type was specified.</param>
        /// <param name="payloadTypeName">The name of the payload type, or null if no payload type was specified.</param>
        /// <param name="defaultPayloadType">The default payload type if none is specified in the payload;
        /// for ATOM this is Edm.String, for JSON it is null since there is no payload type name for primitive types in the payload.</param>
        /// <param name="model">The model to use.</param>
        /// <param name="messageReaderSettings">The message reader settings to use.</param>
        /// <returns>The target type reference to use for parsing the value. This method never returns null.</returns>
        internal static IEdmTypeReference ResolveAndValidatePrimitiveTargetType(
            IEdmTypeReference expectedTypeReference,
            EdmTypeKind payloadTypeKind,
            IEdmType payloadType,
            string payloadTypeName,
            IEdmType defaultPayloadType,
            IEdmModel model,
            ODataMessageReaderSettings messageReaderSettings)
        {
            Debug.Assert(messageReaderSettings != null, "messageReaderSettings != null");
            Debug.Assert(
                payloadTypeKind == EdmTypeKind.Primitive || payloadTypeKind == EdmTypeKind.Complex ||
                payloadTypeKind == EdmTypeKind.Entity || payloadTypeKind == EdmTypeKind.Collection ||
                payloadTypeKind == EdmTypeKind.None || payloadTypeKind == EdmTypeKind.TypeDefinition,
                "The payload type kind must be one of None, Primitive, Complex, Entity, Collection or TypeDefinition.");
            Debug.Assert(
                expectedTypeReference == null || expectedTypeReference.TypeKind() == EdmTypeKind.Primitive,
                "This method only works for primitive expected type.");
            Debug.Assert(
                payloadType == null || payloadType.TypeKind == payloadTypeKind,
                "The payload type kind must match the payload type if that is available.");
            Debug.Assert(payloadType == null || payloadTypeName != null, "If we have a payload type, we must have its name as well.");

            bool useExpectedTypeOnlyForTypeResolution = messageReaderSettings.ReaderBehavior.TypeResolver != null && payloadType != null;

            if (expectedTypeReference != null && !useExpectedTypeOnlyForTypeResolution)
            {
                ValidateTypeSupported(expectedTypeReference);
            }

            // Validate type kinds except for open properties or when in lax mode, but only if primitive type conversion is enabled.
            // If primitive type conversion is disabled, the type kind must match, no matter what validation mode is used.
            // The rules for primitive types are:
            // - In the strict mode the payload value must be convertible to the expected type. So the payload type must be a primitive type.
            // - In the lax mode the payload type is ignored, so its type kind is not verified in any way
            // - If the DisablePrimitiveTypeConversion == true, the lax/strict mode doesn't matter and we will read the payload value on its own.
            //     In this case we require the payload value to always be a primitive type (so type kinds must match), but it may not be convertible
            //     to the expected type, it will still be reported to the caller. 
            if (payloadTypeKind != EdmTypeKind.None && (messageReaderSettings.DisablePrimitiveTypeConversion || !messageReaderSettings.DisableStrictMetadataValidation))
            {
                // Make sure that the type kinds match.
                ValidationUtils.ValidateTypeKind(payloadTypeKind, EdmTypeKind.Primitive, payloadTypeName);
            }

            if (!model.IsUserModel())
            {
                // If there's no model, it means we should not have the expected type either, and that there's no type to use,
                // no metadata validation to perform.
                Debug.Assert(expectedTypeReference == null, "If we don't have a model, we must not have expected type either.");
                return MetadataUtils.GetNullablePayloadTypeReference(payloadType ?? defaultPayloadType);
            }

            // If the primitive type conversion is off, use the payload type always.
            // If there's no expected type or the expected type is ignored, use the payload type as well.
            if (expectedTypeReference == null || useExpectedTypeOnlyForTypeResolution || messageReaderSettings.DisablePrimitiveTypeConversion)
            {
                // If there's no payload type, use the default payload type.
                // Note that in collections the items without type should inherit the type name from the collection, in that case the expectedTypeReference
                // is never null (assuming we do have a model), so we won't get here.
                return MetadataUtils.GetNullablePayloadTypeReference(payloadType ?? defaultPayloadType);
            }

            // The server ignores the payload type when expected type is specified
            // The server is going to use lax mode everywhere so this is not an issue.
            if (messageReaderSettings.DisableStrictMetadataValidation)
            {
                // Lax validation logic
                // Always use the expected type, the payload type is ignored.
                return expectedTypeReference;
            }

            // Strict validation logic
            // We assume the expected type in the case where no payload type is specified
            // for a primitive value (in strict mode); if no expected type is available we assume Edm.String.
            if (payloadType != null)
            {
                // The payload type must be convertible to the expected type.
                // Note that we compare the type definitions, since we want to ignore nullability (the payload type doesn't specify nullability).
                if (!MetadataUtilsCommon.CanConvertPrimitiveTypeTo(
                    null /* sourceNodeOrNull */,
                    (IEdmPrimitiveType)payloadType.AsActualType(),
                    (IEdmPrimitiveType)(expectedTypeReference.Definition)))
                {
                    throw new ODataException(Strings.ValidationUtils_IncompatibleType(payloadTypeName, expectedTypeReference.ODataFullName()));
                }
            }

            // Read using the expected type. 
//.........这里部分代码省略.........
开发者ID:rossjempson,项目名称:odata.net,代码行数:101,代码来源:ReaderValidationUtils.cs

示例13: ValidateIfTypeNameMissing

 /// <summary>
 /// Validate if type name is missing
 /// </summary>
 /// <param name="typeName">Type name of the property to be validated.</param>
 /// <param name="model">The model to use.</param>
 /// <param name="isOpenPropertyType">If the property is open.</param>
 private static void ValidateIfTypeNameMissing(string typeName, IEdmModel model, bool isOpenPropertyType)
 {
     // if we have metadata, the type name of an open property value must not be null
     if (typeName == null && model.IsUserModel() && isOpenPropertyType)
     {
         throw new ODataException(Strings.WriterValidationUtils_MissingTypeNameWithMetadata);
     }
 }
开发者ID:TomDu,项目名称:odata.net,代码行数:14,代码来源:TypeNameOracle.cs

示例14: ResolveAndValidateTypeFromNameAndMetadata

        /// <summary>
        /// Resolve a type name against the provided <paramref name="model"/>. If not payload type name is specified,
        /// derive the type from the model type (if available).
        /// </summary>
        /// <param name="model">The model to use.</param>
        /// <param name="typeReferenceFromMetadata">The type inferred from the model or null if the model is not a user model.</param>
        /// <param name="typeName">The type name to be resolved.</param>
        /// <param name="typeKindFromValue">The expected type kind of the resolved type.</param>
        /// <param name="isOpenPropertyType">True if the type name belongs to an open property.</param>
        /// <returns>A type for the <paramref name="typeName"/> or null if no type name is specified and no metadata is available.</returns>
        private static IEdmTypeReference ResolveAndValidateTypeFromNameAndMetadata(IEdmModel model, IEdmTypeReference typeReferenceFromMetadata, string typeName, EdmTypeKind typeKindFromValue, bool isOpenPropertyType)
        {
            Debug.Assert(model != null, "model != null");
            Debug.Assert(
                typeKindFromValue == EdmTypeKind.Complex || typeKindFromValue == EdmTypeKind.Collection || typeKindFromValue == EdmTypeKind.Enum,
                "Only complex or collection or enum types are supported by this method. This method assumes that the types in question don't support inheritance.");

            // if we have metadata, the type name of an open property value must not be null
            if (typeName == null && model.IsUserModel() && isOpenPropertyType)
            {
                throw new ODataException(Strings.WriterValidationUtils_MissingTypeNameWithMetadata);
            }

            // starting from enum type, we want to skip validation (but still let the above makes sure open type's enum value has .TypeName)
            if (typeKindFromValue == EdmTypeKind.Enum)
            {
                return null;
            }

            IEdmType typeFromValue = typeName == null ? null : ResolveAndValidateTypeName(model, typeName, typeKindFromValue);
            if (typeReferenceFromMetadata != null)
            {
                ValidationUtils.ValidateTypeKind(typeKindFromValue, typeReferenceFromMetadata.TypeKind(), typeFromValue == null ? null : typeFromValue.ODataFullName());
            }

            IEdmTypeReference typeReferenceFromValue = ValidateMetadataType(typeReferenceFromMetadata, typeFromValue == null ? null : typeFromValue.ToTypeReference());
            if (typeKindFromValue == EdmTypeKind.Collection && typeReferenceFromValue != null)
            {
                // update nullability from metadata
                if (typeReferenceFromMetadata != null)
                {
                    typeReferenceFromValue = typeReferenceFromMetadata;
                }

                // validate that the collection type represents a valid Collection type (e.g., is unordered).
                typeReferenceFromValue = ValidationUtils.ValidateCollectionType(typeReferenceFromValue);
            }

            return typeReferenceFromValue;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:50,代码来源:TypeNameOracle.cs

示例15: ShouldValidateComplexPropertyNullValue

        /// <summary>
        /// Null validation of complex properties will be skipped if edm version is less than v3 and data service version exists.
        /// In such cases, the provider decides what should be done if a null value is stored on a non-nullable complex property.
        /// </summary>
        /// <param name="model">The model containing the complex property.</param>
        /// <returns>True if complex property should be validated for null values.</returns>
        internal static bool ShouldValidateComplexPropertyNullValue(IEdmModel model)
        {
            // Null validation of complex properties will be skipped if edm version < v3 and data service version exists.
            Debug.Assert(model != null, "For null validation model is required.");
            Debug.Assert(model.IsUserModel(), "For complex properties, the model should be user model.");

            return true;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:14,代码来源:ValidationUtils.cs


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