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


C# IEdmTypeReference.IsODataTypeDefinitionTypeKind方法代码示例

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


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

示例1: ValidateNullValueAllowed

        /// <summary>
        /// Validates that the specified <paramref name="expectedValueTypeReference"/> allows null values.
        /// </summary>
        /// <param name="expectedValueTypeReference">The expected type for the value, or null if no such type is available.</param>
        /// <param name="validateNullValue">true to validate the null value; otherwise false.</param>
        /// <param name="model">The model to use to get the OData-Version.</param>
        /// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
        /// <param name="isDynamicProperty">Indicates whether the property is dynamic or unknown.</param>
        private static void ValidateNullValueAllowed(IEdmTypeReference expectedValueTypeReference, bool validateNullValue, IEdmModel model, string propertyName, bool? isDynamicProperty)
        {
            Debug.Assert(model != null, "For null validation, model is required.");

            if (validateNullValue && expectedValueTypeReference != null)
            {
                Debug.Assert(
                    expectedValueTypeReference.IsODataPrimitiveTypeKind() ||
                    expectedValueTypeReference.IsODataTypeDefinitionTypeKind() ||
                    expectedValueTypeReference.IsODataEnumTypeKind() ||
                    expectedValueTypeReference.IsODataComplexTypeKind() ||
                    expectedValueTypeReference.IsNonEntityCollectionType(),
                    "Only primitive, type definition, Enum, complex and collection types are supported by this method.");

                if (expectedValueTypeReference.IsODataPrimitiveTypeKind())
                {
                    // COMPAT 55: WCF DS allows null values for non-nullable properties
                    // For now ODataLib will always fail on null value when it is to be reported for a non-nullable property
                    // We should add a knob since WCF DS might need the different behavior.
                    if (!expectedValueTypeReference.IsNullable)
                    {
                        ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
                    }
                }
                else if (expectedValueTypeReference.IsODataEnumTypeKind())
                {
                    if (!expectedValueTypeReference.IsNullable)
                    {
                        ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
                    }
                }
                else if (expectedValueTypeReference.IsNonEntityCollectionType())
                {
                    if (isDynamicProperty != true)
                    {
                        ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
                    }
                }
                else if (expectedValueTypeReference.IsODataComplexTypeKind())
                {
                    if (ValidationUtils.ShouldValidateComplexPropertyNullValue(model))
                    {
                        IEdmComplexTypeReference complexTypeReference = expectedValueTypeReference.AsComplex();
                        if (!complexTypeReference.IsNullable)
                        {
                            ThrowNullValueForNonNullableTypeException(expectedValueTypeReference, propertyName);
                        }
                    }
                }
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:59,代码来源:ReaderValidationUtils.cs

示例2: ValidateMetadataPrimitiveType

        /// <summary>
        /// Validates that the expected primitive type or type definition matches the actual primitive type.
        /// </summary>
        /// <param name="expectedTypeReference">The expected type.</param>
        /// <param name="typeReferenceFromValue">The actual type.</param>
        internal static void ValidateMetadataPrimitiveType(IEdmTypeReference expectedTypeReference, IEdmTypeReference typeReferenceFromValue)
        {
            Debug.Assert(expectedTypeReference != null && (expectedTypeReference.IsODataPrimitiveTypeKind() || expectedTypeReference.IsODataTypeDefinitionTypeKind()), "expectedTypeReference must be a primitive type or type definition.");
            Debug.Assert(typeReferenceFromValue != null && typeReferenceFromValue.IsODataPrimitiveTypeKind(), "typeReferenceFromValue must be a primitive type.");

            IEdmType expectedType = expectedTypeReference.Definition;
            IEdmPrimitiveType typeFromValue = (IEdmPrimitiveType)typeReferenceFromValue.Definition;

            // The two primitive types match if they have the same definition and either both or only the 
            // expected type is nullable
            // NOTE: for strings and binary values we must not check nullability here because the type reference 
            //       from the value is always nullable since C# has no way to express non-nullable strings.
            //       However, this codepath is only hit if the value is not 'null' so we can assign a non-null 
            //       value to both nullable and non-nullable string/binary types.
            bool nullableCompatible = expectedTypeReference.IsNullable == typeReferenceFromValue.IsNullable ||
                expectedTypeReference.IsNullable && !typeReferenceFromValue.IsNullable ||
                !MetadataUtilsCommon.IsODataValueType(typeReferenceFromValue);

            bool typeCompatible = expectedType.IsAssignableFrom(typeFromValue);
            if (!nullableCompatible || !typeCompatible)
            {
                // incompatible type name for value!
                throw new ODataException(Strings.ValidationUtils_IncompatiblePrimitiveItemType(
                    typeReferenceFromValue.ODataFullName(),
                    typeReferenceFromValue.IsNullable,
                    expectedTypeReference.ODataFullName(),
                    expectedTypeReference.IsNullable));
            }
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:34,代码来源:ValidationUtils.cs

示例3: ReadCollectionItem

        /// <summary>
        /// Reads an item in the collection.
        /// </summary>
        /// <param name="expectedItemTypeReference">The expected type of the item to read.</param>
        /// <param name="collectionValidator">The collection validator instance if no expected item type has been specified; otherwise null.</param>
        /// <returns>The value of the collection item that was read; this can be an ODataComplexValue, a primitive value or 'null'.</returns>
        /// <remarks>
        /// Pre-Condition:  The first node of the item in the collection
        ///                 NOTE: this method will throw if the node is not
        ///                 JsonNodeType.StartObject:    for a complex item
        ///                 JsonNodeType.PrimitiveValue: for a primitive item
        /// Post-Condition: The reader is positioned on the first node of the next item or an EndArray node if there are no more items in the collection
        /// </remarks>
        internal object ReadCollectionItem(IEdmTypeReference expectedItemTypeReference, CollectionWithoutExpectedTypeValidator collectionValidator)
        {
            Debug.Assert(
                expectedItemTypeReference == null ||
                expectedItemTypeReference.IsODataPrimitiveTypeKind() ||
                expectedItemTypeReference.IsODataComplexTypeKind() ||
                expectedItemTypeReference.IsODataEnumTypeKind() ||
                expectedItemTypeReference.IsODataTypeDefinitionTypeKind(),
                "If an expected type is specified, it must be a primitive, complex type, enum type or type definition.");
            this.JsonReader.AssertNotBuffering();

            object item = this.ReadNonEntityValue(
                /*payloadTypeName*/ null,
                expectedItemTypeReference, 
                this.duplicatePropertyNamesChecker, 
                collectionValidator,
                /*validateNullValue*/ true,
                /*isTopLevelPropertyValue*/ false,
                /*insideComplexValue*/ false,
                /*propertyName*/ null);

            this.JsonReader.AssertNotBuffering();

            return item;
        }
开发者ID:TomDu,项目名称:odata.net,代码行数:38,代码来源:ODataJsonLightCollectionDeserializer.cs

示例4: ValidateIsExpectedPrimitiveType

        /// <summary>
        /// Validates that a given primitive value is of the expected (primitive) type.
        /// </summary>
        /// <param name="value">The value to check.</param>
        /// <param name="valuePrimitiveTypeReference">The primitive type reference for the value - some callers have this already, so we save the lookup here.</param>
        /// <param name="expectedTypeReference">The expected type for the value.</param>
        /// <param name="bypassValidation">Bypass the validation if it is true.</param>
        /// <remarks>
        /// Some callers have the primitive type reference already resolved (from the value type)
        /// so this method is an optimized version to not lookup the primitive type reference again.
        /// </remarks>
        internal static void ValidateIsExpectedPrimitiveType(object value, IEdmPrimitiveTypeReference valuePrimitiveTypeReference, IEdmTypeReference expectedTypeReference, bool bypassValidation = false)
        {
            Debug.Assert(value != null, "value != null");
            Debug.Assert(expectedTypeReference != null, "expectedTypeReference != null");

            if (bypassValidation)
            {
                return;
            }

            if (valuePrimitiveTypeReference == null)
            {
                throw new ODataException(Strings.ValidationUtils_UnsupportedPrimitiveType(value.GetType().FullName));
            }

            Debug.Assert(valuePrimitiveTypeReference.IsEquivalentTo(EdmLibraryExtensions.GetPrimitiveTypeReference(value.GetType())), "The value and valuePrimitiveTypeReference don't match.");
            if (!expectedTypeReference.IsODataPrimitiveTypeKind() && !expectedTypeReference.IsODataTypeDefinitionTypeKind())
            {
                // non-primitive type found for primitive value.
                throw new ODataException(Strings.ValidationUtils_NonPrimitiveTypeForPrimitiveValue(expectedTypeReference.ODataFullName()));
            }

            ValidateMetadataPrimitiveType(expectedTypeReference, valuePrimitiveTypeReference);
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:35,代码来源:ValidationUtils.cs


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