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


C# IEdmTypeReference.IsODataEntityTypeKind方法代码示例

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


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

示例1: ReadTopLevelProperty

        /// <summary>
        /// This method creates and reads the property from the input and 
        /// returns an <see cref="ODataProperty"/> representing the read property.
        /// </summary>
        /// <param name="expectedProperty">The <see cref="IEdmProperty"/> producing the property to be read.</param>
        /// <param name="expectedPropertyTypeReference">The expected type of the property to read.</param>
        /// <returns>An <see cref="ODataProperty"/> representing the read property.</returns>
        internal ODataProperty ReadTopLevelProperty(IEdmStructuralProperty expectedProperty, IEdmTypeReference expectedPropertyTypeReference)
        {
            Debug.Assert(
                expectedPropertyTypeReference == null || !expectedPropertyTypeReference.IsODataEntityTypeKind(),
                "If the expected type is specified it must not be an entity type.");
            Debug.Assert(this.XmlReader != null, "this.xmlReader != null");

            this.ReadPayloadStart();
            Debug.Assert(this.XmlReader.NodeType == XmlNodeType.Element, "The XML reader must be positioned on an Element.");

            // For compatibility with WCF DS Server we need to be able to read the property element in any namespace, not just the OData namespace.
            if (!this.UseServerFormatBehavior && !this.XmlReader.NamespaceEquals(this.XmlReader.ODataMetadataNamespace))
            {
                throw new ODataException(ODataErrorStrings.ODataAtomPropertyAndValueDeserializer_TopLevelPropertyElementWrongNamespace(this.XmlReader.NamespaceURI, this.XmlReader.ODataMetadataNamespace));
            }

            // this is a top level property so EPM does not apply hence it is safe to say that EPM is not present
            this.AssertRecursionDepthIsZero();
            string expectedPropertyName = ReaderUtils.GetExpectedPropertyName(expectedProperty);
            ODataProperty property = this.ReadProperty(
                true,
                expectedPropertyName,
                expectedPropertyTypeReference,
                /*nullValueReadBehaviorKind*/ ODataNullValueBehaviorKind.Default);
            this.AssertRecursionDepthIsZero();
        
            Debug.Assert(property != null, "If we don't ignore null values the property must not be null.");

            this.ReadPayloadEnd();

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

示例2: CanConvertTo

 internal static bool CanConvertTo(IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
 {
     if (sourceReference.IsEquivalentTo(targetReference))
     {
         return true;
     }
     if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
     {
         return ((IEdmStructuredType) targetReference.Definition).IsAssignableFrom(((IEdmStructuredType) sourceReference.Definition));
     }
     if (IsOpenPropertyType(targetReference))
     {
         return true;
     }
     IEdmPrimitiveTypeReference type = sourceReference.AsPrimitiveOrNull();
     IEdmPrimitiveTypeReference reference2 = targetReference.AsPrimitiveOrNull();
     return (((type != null) && (reference2 != null)) && MetadataUtilsCommon.CanConvertPrimitiveTypeTo(type.PrimitiveDefinition(), reference2.PrimitiveDefinition()));
 }
开发者ID:nickchal,项目名称:pash,代码行数:18,代码来源:TypePromotionUtils.cs

示例3: ReadNonEntityValueImplementation

        /// <summary>
        /// Reads the primitive, complex or collection value.
        /// </summary>
        /// <param name="expectedTypeReference">The expected type reference of the value.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use (cached), or null if new one should be created.</param>
        /// <param name="collectionValidator">The collection validator instance if no expected item type has been specified; otherwise null.</param>
        /// <param name="validateNullValue">true to validate a null value (i.e., throw if a null value is being written for a non-nullable property); otherwise false.</param>
        /// <param name="propertyName">The name of the property whose value is being read, if applicable (used for error reporting).</param>
        /// <returns>The value read (null, primitive CLR value, ODataComplexValue or ODataCollectionValue).</returns>
        /// <remarks>
        /// Pre-Condition:   XmlNodeType.Element    - The XML element containing the value to read (also the attributes will be read from it)
        /// Post-Condition:  XmlNodeType.EndElement - The end tag of the element.
        ///                  XmlNodeType.Element    - The empty element node.
        /// </remarks>
        private object ReadNonEntityValueImplementation(IEdmTypeReference expectedTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, CollectionWithoutExpectedTypeValidator collectionValidator, bool validateNullValue, string propertyName)
        {
            this.AssertXmlCondition(XmlNodeType.Element);
            Debug.Assert(
                expectedTypeReference == null || !expectedTypeReference.IsODataEntityTypeKind(),
                "Only primitive, complex or collection types can be read by this method.");
            Debug.Assert(
                expectedTypeReference == null || collectionValidator == null,
                "If an expected value type reference is specified, no collection validator must be provided.");
            this.XmlReader.AssertNotBuffering();

            // Read the attributes looking for m:type and m:null
            string payloadTypeName;
            bool isNull;
            this.ReadNonEntityValueAttributes(out payloadTypeName, out isNull);

            object result;
            if (isNull)
            {
                result = this.ReadNullValue(expectedTypeReference, validateNullValue, propertyName);
            }
            else
            {
                // If we could derive the item type name from the collection's type name and no type name was specified in the payload
                // fill it in now.
                EdmTypeKind payloadTypeKind;
                bool derivedItemTypeNameFromCollectionTypeName = false;
                if (collectionValidator != null && payloadTypeName == null)
                {
                    payloadTypeName = collectionValidator.ItemTypeNameFromCollection;
                    payloadTypeKind = collectionValidator.ItemTypeKindFromCollection;
                    derivedItemTypeNameFromCollectionTypeName = payloadTypeKind != EdmTypeKind.None;
                }

                // Resolve the payload type name and compute the target type kind and target type reference.
                SerializationTypeNameAnnotation serializationTypeNameAnnotation;
                EdmTypeKind targetTypeKind;
                IEdmTypeReference targetTypeReference = ReaderValidationUtils.ResolvePayloadTypeNameAndComputeTargetType(
                    EdmTypeKind.None,
                    /*defaultPrimitivePayloadType*/ edmStringType,
                    expectedTypeReference,
                    payloadTypeName,
                    this.Model,
                    this.MessageReaderSettings,
                    this.GetNonEntityValueKind,
                    out targetTypeKind,
                    out serializationTypeNameAnnotation);

                if (derivedItemTypeNameFromCollectionTypeName)
                {
                    Debug.Assert(
                        serializationTypeNameAnnotation == null,
                        "If we derived the item type name from the collection type name we must not have created a serialization type name annotation.");
                    serializationTypeNameAnnotation = new SerializationTypeNameAnnotation { TypeName = null };
                }

                // If we have no expected type make sure the collection items are of the same kind and specify the same name.
                if (collectionValidator != null)
                {
                    Debug.Assert(expectedTypeReference == null, "If a collection validator is specified there must not be an expected value type reference.");
                    collectionValidator.ValidateCollectionItem(payloadTypeName, targetTypeKind);
                }

                switch (targetTypeKind)
                {
                    case EdmTypeKind.Enum:
                        Debug.Assert(targetTypeReference != null && targetTypeReference.IsODataEnumTypeKind(), "Expected an OData Enum type.");
                        result = this.ReadEnumValue(targetTypeReference.AsEnum());
                        break;

                    case EdmTypeKind.Primitive:
                        Debug.Assert(targetTypeReference != null && targetTypeReference.IsODataPrimitiveTypeKind(), "Expected an OData primitive type.");
                        result = this.ReadPrimitiveValue(targetTypeReference.AsPrimitive());
                        break;

                    case EdmTypeKind.Complex:
                        Debug.Assert(targetTypeReference == null || targetTypeReference.IsComplex(), "Expected a complex type.");
                        result = this.ReadComplexValue(
                            targetTypeReference == null ? null : targetTypeReference.AsComplex(),
                            payloadTypeName,
                            serializationTypeNameAnnotation,
                            duplicatePropertyNamesChecker);
                        break;

                    case EdmTypeKind.Collection:
                        IEdmCollectionTypeReference collectionTypeReference = ValidationUtils.ValidateCollectionType(targetTypeReference);
//.........这里部分代码省略.........
开发者ID:rossjempson,项目名称:odata.net,代码行数:101,代码来源:ODataAtomPropertyAndValueDeserializer.cs

示例4: ReadNonEntityValueImplementation

        private object ReadNonEntityValueImplementation(
            string payloadTypeName,
            IEdmTypeReference expectedTypeReference,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            CollectionWithoutExpectedTypeValidator collectionValidator,
            bool validateNullValue,
            bool isTopLevelPropertyValue,
            bool insideComplexValue,
            string propertyName,
            bool? isDynamicProperty = null)
        {
            Debug.Assert(
                this.JsonReader.NodeType == JsonNodeType.PrimitiveValue || this.JsonReader.NodeType == JsonNodeType.StartObject ||
                this.JsonReader.NodeType == JsonNodeType.StartArray || (insideComplexValue && (this.JsonReader.NodeType == JsonNodeType.Property || this.JsonReader.NodeType == JsonNodeType.EndObject)),
                "Pre-Condition: expected JsonNodeType.PrimitiveValue or JsonNodeType.StartObject or JsonNodeType.StartArray or JsonNodeTypeProperty (when inside complex value).");
            Debug.Assert(
                expectedTypeReference == null || !expectedTypeReference.IsODataEntityTypeKind(),
                "Only primitive, complex or collection types can be read by this method.");
            Debug.Assert(
                expectedTypeReference == null || collectionValidator == null,
                "If an expected value type reference is specified, no collection validator must be provided.");

            bool valueIsJsonObject = this.JsonReader.NodeType == JsonNodeType.StartObject;
            bool payloadTypeNameFromPropertyAnnotation = !insideComplexValue && payloadTypeName != null;

            bool typeNameFoundInPayload = false;
            if (valueIsJsonObject || insideComplexValue)
            {
                // If we have an object value initialize the duplicate property names checker
                if (duplicatePropertyNamesChecker == null)
                {
                    duplicatePropertyNamesChecker = this.CreateDuplicatePropertyNamesChecker();
                }
                else
                {
                    duplicatePropertyNamesChecker.Clear();
                }

                // Read the payload type name
                if (!insideComplexValue)
                {
                    string typeName;
                    typeNameFoundInPayload = this.TryReadPayloadTypeFromObject(
                        duplicatePropertyNamesChecker,
                        insideComplexValue,
                        out typeName);
                    if (typeNameFoundInPayload)
                    {
                        payloadTypeName = typeName;
                    }
                }
            }

            SerializationTypeNameAnnotation serializationTypeNameAnnotation;
            EdmTypeKind targetTypeKind;
            IEdmTypeReference targetTypeReference = ReaderValidationUtils.ResolvePayloadTypeNameAndComputeTargetType(
                EdmTypeKind.None,
                /*defaultPrimitivePayloadType*/ null,
                expectedTypeReference,
                payloadTypeName,
                this.Model,
                this.MessageReaderSettings,
                this.GetNonEntityValueKind,
                out targetTypeKind,
                out serializationTypeNameAnnotation);

            object result;

            // Try to read a null value
            if (ODataJsonReaderCoreUtils.TryReadNullValue(this.JsonReader, this.JsonLightInputContext, targetTypeReference, validateNullValue, propertyName, isDynamicProperty))
            {
                if (isTopLevelPropertyValue)
                {
                    // For a top-level property value a special null marker object has to be used to indicate  a null value.
                    // If we find a null value for a property at the top-level, it is an invalid payload
                    throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_TopLevelPropertyWithPrimitiveNullValue(ODataAnnotationNames.ODataNull, JsonLightConstants.ODataNullAnnotationTrueValue));
                }
                else if (validateNullValue && (targetTypeReference != null) && (!targetTypeReference.IsNullable))
                {
                    // For dynamic collection property, we should allow null value to be assigned to it.
                    if (targetTypeKind != EdmTypeKind.Collection || isDynamicProperty != true)
                    {
                        // A null value was found for the property named '{0}', which has the expected type '{1}[Nullable=False]'. The expected type '{1}[Nullable=False]' does not allow null values.
                        throw new ODataException(ODataErrorStrings.ReaderValidationUtils_NullNamedValueForNonNullableType(propertyName, targetTypeReference.FullName()));
                    }
                }

                result = null;
            }
            else
            {
                Debug.Assert(
                    !valueIsJsonObject || this.JsonReader.NodeType == JsonNodeType.Property || this.JsonReader.NodeType == JsonNodeType.EndObject,
                    "If the value was an object the reader must be on either property or end object.");
                switch (targetTypeKind)
                {
                    case EdmTypeKind.Primitive:
                        Debug.Assert(targetTypeReference == null || targetTypeReference.IsODataPrimitiveTypeKind(), "Expected an OData primitive type.");
                        IEdmPrimitiveTypeReference primitiveTargetTypeReference = targetTypeReference == null ? null : targetTypeReference.AsPrimitive();

//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:odata.net,代码行数:101,代码来源:ODataJsonLightPropertyAndValueDeserializer.cs

示例5: ReadTopLevelPropertyImplementation

        /// <summary>
        /// This method creates an reads the property from the input and 
        /// returns an <see cref="ODataProperty"/> representing the read property.
        /// </summary>
        /// <param name="expectedPropertyTypeReference">The expected type reference of the property to read.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use.</param>
        /// <returns>An <see cref="ODataProperty"/> representing the read property.</returns>
        /// <remarks>
        /// The method assumes that the ReadPayloadStart has already been called and it will not call ReadPayloadEnd.
        /// </remarks>
        private ODataProperty ReadTopLevelPropertyImplementation(IEdmTypeReference expectedPropertyTypeReference, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker)
        {
            Debug.Assert(
                expectedPropertyTypeReference == null || !expectedPropertyTypeReference.IsODataEntityTypeKind(),
                "If the expected type is specified it must not be an entity type.");
            Debug.Assert(duplicatePropertyNamesChecker != null, "duplicatePropertyNamesChecker != null");

            expectedPropertyTypeReference = this.UpdateExpectedTypeBasedOnContextUri(expectedPropertyTypeReference);

            object propertyValue = missingPropertyValue;
            var customInstanceAnnotations = new Collection<ODataInstanceAnnotation>();

            // Check for the special top-level null marker
            if (this.IsTopLevelNullValue())
            {
                // NOTE: when reading a null value we will never ask the type resolver (if present) to resolve the
                //       type; we always fall back to the expected type.
                ReaderValidationUtils.ValidateNullValue(
                    this.Model,
                    expectedPropertyTypeReference,
                    this.MessageReaderSettings,
                    /*validateNullValue*/ true,
                    /*propertyName*/ null);

                // We don't allow properties or non-custom annotations in the null payload.
                this.ValidateNoPropertyInNullPayload(duplicatePropertyNamesChecker);

                propertyValue = null;
            }
            else
            {
                string payloadTypeName = null;
                if (this.ReadingComplexProperty(duplicatePropertyNamesChecker, expectedPropertyTypeReference, out payloadTypeName))
                {
                    // Figure out whether we are reading a complex property or not; complex properties are not wrapped while all others are.
                    // Since we don't have metadata in all cases (open properties), we have to detect the type in some cases.
                    this.AssertJsonCondition(JsonNodeType.Property, JsonNodeType.EndObject);

                    // Now read the property value
                    propertyValue = this.ReadNonEntityValue(
                        payloadTypeName,
                        expectedPropertyTypeReference,
                        duplicatePropertyNamesChecker,
                        /*collectionValidator*/ null,
                        /*validateNullValue*/ true,
                        /*isTopLevelPropertyValue*/ true,
                        /*insideComplexValue*/ true,
                        /*propertyName*/ null);
                }
                else
                {
                    bool isReordering = this.JsonReader is ReorderingJsonReader;

                    Func<string, object> propertyAnnotationReaderForTopLevelProperty =
                        annotationName => { throw new ODataException(ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_UnexpectedODataPropertyAnnotation(annotationName)); };

                    // Read through all top-level properties, ignore the ones with reserved names (i.e., reserved 
                    // characters in their name) and throw if we find none or more than one properties without reserved name.
                    while (this.JsonReader.NodeType == JsonNodeType.Property)
                    {
                        this.ProcessProperty(
                            duplicatePropertyNamesChecker,
                            propertyAnnotationReaderForTopLevelProperty,
                            (propertyParsingResult, propertyName) =>
                            {
                                switch (propertyParsingResult)
                                {
                                    case PropertyParsingResult.ODataInstanceAnnotation:
                                        if (string.CompareOrdinal(ODataAnnotationNames.ODataType, propertyName) == 0)
                                        {
                                            // When we are not using the reordering reader we have to ensure that the 'odata.type' property appears before
                                            // the 'value' property; otherwise we already scanned ahead and read the type name and have to now
                                            // ignore it (even if it is after the 'value' property).
                                            if (isReordering)
                                            {
                                                this.JsonReader.SkipValue();
                                            }
                                            else
                                            {
                                                if (!object.ReferenceEquals(missingPropertyValue, propertyValue))
                                                {
                                                    throw new ODataException(
                                                        ODataErrorStrings.ODataJsonLightPropertyAndValueDeserializer_TypePropertyAfterValueProperty(ODataAnnotationNames.ODataType, JsonLightConstants.ODataValuePropertyName));
                                                }

                                                payloadTypeName = this.ReadODataTypeAnnotationValue();
                                            }
                                        }
                                        else
                                        {
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:odata.net,代码行数:101,代码来源:ODataJsonLightPropertyAndValueDeserializer.cs

示例6: ReadNonEntityValueImplementation

        /// <summary>
        /// Reads a primitive, complex or collection value.
        /// </summary>
        /// <param name="expectedTypeReference">The expected type reference of the property value.</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use - if null the method should create a new one if necessary.</param>
        /// <param name="collectionValidator">The collection validator instance if no expected item type has been specified; otherwise null.</param>
        /// <param name="validateNullValue">true to validate null values; otherwise false.</param>
        /// <returns>The value of the property read.</returns>
        /// <remarks>
        /// Pre-Condition:  JsonNodeType.PrimitiveValue   - the value of the property is a primitive value
        ///                 JsonNodeType.StartObject      - the value of the property is an object
        ///                 JsonNodeType.StartArray       - the value of the property is an array - method will fail in this case.
        /// Post-Condition: almost anything - the node after the property value.
        ///                 
        /// Returns the value of the property read, which can be one of:
        /// - null
        /// - primitive value
        /// - <see cref="ODataComplexValue"/>
        /// - <see cref="ODataCollectionValue"/>
        /// </remarks>
        private object ReadNonEntityValueImplementation(
            IEdmTypeReference expectedTypeReference,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            CollectionWithoutExpectedTypeValidator collectionValidator,
            bool validateNullValue)
        {
            // TODO: can we ever get a non-null collection validator here? That would mean that we don't have
            //       an expected type; double-check
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(
                this.JsonReader.NodeType == JsonNodeType.PrimitiveValue || this.JsonReader.NodeType == JsonNodeType.StartObject || this.JsonReader.NodeType == JsonNodeType.StartArray,
                "Pre-Condition: expected JsonNodeType.PrimitiveValue or JsonNodeType.StartObject or JsonNodeType.StartArray");
            Debug.Assert(
                expectedTypeReference == null || !expectedTypeReference.IsODataEntityTypeKind(),
                "Only primitive, complex or collection types can be read by this method.");
            Debug.Assert(
                expectedTypeReference == null || collectionValidator == null,
                "If an expected value type reference is specified, no collection validator must be provided.");
            this.JsonReader.AssertNotBuffering();

            // Property values can be only primitives or objects. No property can have a JSON array value.
            JsonNodeType nodeType = this.JsonReader.NodeType;
            if (nodeType == JsonNodeType.StartArray)
            {
                throw new ODataException(o.Strings.ODataJsonPropertyAndValueDeserializer_CannotReadPropertyValue(nodeType));
            }

            // Try to read a null value
            object result;
            if (this.TryReadNullValue(expectedTypeReference, validateNullValue))
            {
                result = null;
            }
            else
            {
                // Read the payload type name
                string payloadTypeName = this.FindTypeNameInPayload();

                SerializationTypeNameAnnotation serializationTypeNameAnnotation;
                EdmTypeKind targetTypeKind;
                IEdmTypeReference targetTypeReference = ReaderValidationUtils.ResolvePayloadTypeNameAndComputeTargetType(
                    EdmTypeKind.None,
                    /*defaultPrimitivePayloadType*/ null,
                    expectedTypeReference,
                    payloadTypeName,
                    this.Model,
                    this.MessageReaderSettings,
                    this.Version,
                    this.GetNonEntityValueKind,
                    out targetTypeKind,
                    out serializationTypeNameAnnotation);

                switch (targetTypeKind)
                {
                    case EdmTypeKind.Primitive:
                        Debug.Assert(targetTypeReference == null || targetTypeReference.IsODataPrimitiveTypeKind(), "Expected an OData primitive type.");
                        IEdmPrimitiveTypeReference primitiveTargetTypeReference = targetTypeReference == null ? null : targetTypeReference.AsPrimitive();
                        if (payloadTypeName != null && !primitiveTargetTypeReference.IsSpatial())
                        {
                            throw new ODataException(o.Strings.ODataJsonPropertyAndValueDeserializer_InvalidPrimitiveTypeName(payloadTypeName));
                        }

                        result = this.ReadPrimitiveValueImplementation(
                            primitiveTargetTypeReference,
                            validateNullValue);
                        break;
                    case EdmTypeKind.Complex:
                        Debug.Assert(targetTypeReference == null || targetTypeReference.IsComplex(), "Expected a complex type.");
                        result = this.ReadComplexValueImplementation(
                            targetTypeReference == null ? null : targetTypeReference.AsComplex(),
                            payloadTypeName,
                            serializationTypeNameAnnotation,
                            duplicatePropertyNamesChecker);
                        break;
                    case EdmTypeKind.Collection:
                        Debug.Assert(this.Version >= ODataVersion.V3, "Type resolution should already fail if we would decide to read a collection value in V1/V2 payload.");
                        IEdmCollectionTypeReference collectionTypeReference = ValidationUtils.ValidateCollectionType(targetTypeReference);
                        result = this.ReadCollectionValueImplementation(
                            collectionTypeReference,
                            payloadTypeName,
//.........这里部分代码省略.........
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:101,代码来源:ODataJsonPropertyAndValueDeserializer.cs

示例7: ReadTopLevelProperty

        /// <summary>
        /// This method creates an reads the property from the input and 
        /// returns an <see cref="ODataProperty"/> representing the read property.
        /// </summary>
        /// <param name="expectedPropertyTypeReference">The expected type reference of the property to read.</param>
        /// <returns>An <see cref="ODataProperty"/> representing the read property.</returns>
        internal ODataProperty ReadTopLevelProperty(IEdmTypeReference expectedPropertyTypeReference)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: expected JsonNodeType.None, the reader must not have been used yet.");
            Debug.Assert(
                expectedPropertyTypeReference == null || !expectedPropertyTypeReference.IsODataEntityTypeKind(),
                "If the expected type is specified it must not be an entity type.");
            this.JsonReader.AssertNotBuffering();

            if (!this.Model.IsUserModel())
            {
                throw new ODataException(o.Strings.ODataJsonPropertyAndValueDeserializer_TopLevelPropertyWithoutMetadata);
            }

            // Read the response wrapper "d" if expected.
            this.ReadPayloadStart(false /*isReadingNestedPayload*/);

            string propertyName = null;
            object propertyValue = null;

            // We have to support reading top-level complex values without the { "property": ... } wrapper for open properties
            // in WCF DS Server backward compat mode. (Open property == property without expected type for us).
            if (this.ShouldReadTopLevelPropertyValueWithoutPropertyWrapper(expectedPropertyTypeReference))
            {
                // We will report the value without property wrapper as a property with empty name (this is technically invalid, but it will only happen in WCF DS Server mode).
                propertyName = string.Empty;

                // Read the value directly
                propertyValue = this.ReadNonEntityValue(
                    expectedPropertyTypeReference, 
                    /*duplicatePropertyNamesChecker*/ null, 
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true);
            }
            else
            {
                // Read the start of the object container around the property { "property": ... }
                this.JsonReader.ReadStartObject();

                // Read through all top-level properties, ignore the ones with reserved names (i.e., reserved 
                // characters in their name) and throw if we find none or more than one properties without reserved name.
                bool foundProperty = false;
                string foundPropertyName = null;
                while (this.JsonReader.NodeType == JsonNodeType.Property)
                {
                // Read once - this should be the property
                propertyName = this.JsonReader.ReadPropertyName();

                    if (!ValidationUtils.IsValidPropertyName(propertyName))
                    {
                        // We ignore properties with an invalid name since these are extension points for the future.
                        this.JsonReader.SkipValue();
                    }
                    else
                    {
                        if (foundProperty)
                        {
                            // There should be only one property in the top-level property wrapper that does not have a reserved name.
                            throw new ODataException(o.Strings.ODataJsonPropertyAndValueDeserializer_InvalidTopLevelPropertyPayload);
                        }

                        foundProperty = true;
                        foundPropertyName = propertyName;

                // Now read the property value
                propertyValue = this.ReadNonEntityValue(
                    expectedPropertyTypeReference, 
                    /*duplicatePropertyNamesChecker*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true);
                    }
                }

                if (!foundProperty)
                {
                    // No property found; there should be exactly one property in the top-level property wrapper that does not have a reserved name.
                    throw new ODataException(o.Strings.ODataJsonPropertyAndValueDeserializer_InvalidTopLevelPropertyPayload);
                }

                Debug.Assert(foundPropertyName != null, "foundPropertyName != null");
                propertyName = foundPropertyName;

                // Read over the end object - note that this might be the last node in the input (in case there's no response wrapper)
                this.JsonReader.Read();
            }

            // Read the end of the response wrapper "d" if expected.
            this.ReadPayloadEnd(false /*isReadingNestedPayload*/);

            Debug.Assert(this.JsonReader.NodeType == JsonNodeType.EndOfInput, "Post-Condition: expected JsonNodeType.EndOfInput");
            this.JsonReader.AssertNotBuffering();

            Debug.Assert(propertyName != null, "propertyName != null");

//.........这里部分代码省略.........
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:101,代码来源:ODataJsonPropertyAndValueDeserializer.cs

示例8: CanConvertTo

        internal static bool CanConvertTo(SingleValueNode sourceNodeOrNull, IEdmTypeReference sourceReference, IEdmTypeReference targetReference)
        {
            Debug.Assert(sourceReference != null, "sourceReference != null");
            Debug.Assert(targetReference != null, "targetReference != null");

            //// Copy of the ResourceQueryParser.ExpressionParser.IsCompatibleWith method.

            if (sourceReference.IsEquivalentTo(targetReference))
            {
                return true;
            }

            if (targetReference.IsODataComplexTypeKind() || targetReference.IsODataEntityTypeKind())
            {
                // for structured types, use IsAssignableFrom
                return EdmLibraryExtensions.IsAssignableFrom(
                    (IEdmStructuredType)targetReference.Definition,
                    (IEdmStructuredType)sourceReference.Definition);
            }

            //// This rule stops the parser from considering nullable types as incompatible
            //// with non-nullable types. We have however implemented this rule because we just
            //// access underlying rules. C# requires an explicit .Value access, and EDM has no
            //// nullablity on types and (at the model level) implements null propagation.
            ////
            //// if (sourceReference.IsNullable && !targetReference.IsNullable)
            //// {
            ////     return false;
            //// }

            if (sourceReference.IsEnum() && targetReference.IsEnum())
            {
                if (sourceReference.Definition.IsEquivalentTo(targetReference.Definition))
                {
                    return targetReference.IsNullable() || (!sourceReference.IsNullable());
                }

                return false;
            }

            IEdmPrimitiveTypeReference sourcePrimitiveTypeReference = sourceReference.AsPrimitiveOrNull();
            IEdmPrimitiveTypeReference targetPrimitiveTypeReference = targetReference.AsPrimitiveOrNull();

            if (sourcePrimitiveTypeReference == null || targetPrimitiveTypeReference == null)
            {
                return false;
            }

            return MetadataUtilsCommon.CanConvertPrimitiveTypeTo(sourceNodeOrNull, sourcePrimitiveTypeReference.PrimitiveDefinition(), targetPrimitiveTypeReference.PrimitiveDefinition());
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:50,代码来源:TypePromotionUtils.cs

示例9: SetEpmValue

        /// <summary>
        /// Sets the value read from EPM to a property on an entry.
        /// </summary>
        /// <param name="targetList">The target list, which is a list of properties (on entry or complex value).</param>
        /// <param name="targetTypeReference">The type of the value on which to set the property (can be entity or complex).</param>
        /// <param name="epmInfo">The EPM info for the mapping for which the value was read.</param>
        /// <param name="propertyValue">The property value read, if the value was specified as null then this should be null,
        /// if the value was missing the method should not be called at all.
        /// For primitive properties this should be the string value, for all other properties this should be the exact value type.</param>
        protected void SetEpmValue(
            IList targetList,
            IEdmTypeReference targetTypeReference,
            EntityPropertyMappingInfo epmInfo,
            object propertyValue)
        {
            Debug.Assert(epmInfo != null, "epmInfo != null");
            Debug.Assert(targetTypeReference != null, "targetTypeReference != null");
            Debug.Assert(targetList != null, "targetList != null");
            Debug.Assert(
                targetTypeReference.IsODataEntityTypeKind() || targetTypeReference.IsODataComplexTypeKind(),
                "Only entity and complex types can have an EPM value set on them.");

            this.SetEpmValueForSegment(
                epmInfo,
                0,
                targetTypeReference.AsStructuredOrNull(),
                (List<ODataProperty>)targetList,
                propertyValue);
        }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:29,代码来源:EpmReader.cs


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