예제 #1
0
        private ODataComplexValue ReadComplexValue(IEdmComplexTypeReference complexTypeReference, string payloadTypeName, SerializationTypeNameAnnotation serializationTypeNameAnnotation, DuplicatePropertyNamesChecker duplicatePropertyNamesChecker, bool epmPresent)
        {
            this.IncreaseRecursionDepth();
            ODataComplexValue value2 = new ODataComplexValue();
            IEdmComplexType   type   = (complexTypeReference == null) ? null : ((IEdmComplexType)complexTypeReference.Definition);

            value2.TypeName = (type == null) ? payloadTypeName : type.ODataFullName();
            if (serializationTypeNameAnnotation != null)
            {
                value2.SetAnnotation <SerializationTypeNameAnnotation>(serializationTypeNameAnnotation);
            }
            base.XmlReader.MoveToElement();
            if (duplicatePropertyNamesChecker == null)
            {
                duplicatePropertyNamesChecker = base.CreateDuplicatePropertyNamesChecker();
            }
            else
            {
                duplicatePropertyNamesChecker.Clear();
            }
            List <ODataProperty> properties = new List <ODataProperty>();

            this.ReadPropertiesImplementation(type, properties, duplicatePropertyNamesChecker, epmPresent);
            value2.Properties = new ReadOnlyEnumerable <ODataProperty>(properties);
            this.DecreaseRecursionDepth();
            return(value2);
        }
예제 #2
0
        /// <summary>
        /// Validates that the <paramref name="payloadComplexType"/> is assignable to the <paramref name="expectedComplexType"/>
        /// and fails if it's not.
        /// </summary>
        /// <param name="expectedComplexType">The expected complex type reference, the base type of the ComplexType expected.</param>
        /// <param name="payloadComplexType">The payload complex type reference to validate.</param>
        internal static void ValidateComplexTypeIsAssignable(IEdmComplexType expectedComplexType, IEdmComplexType payloadComplexType)
        {
            Debug.Assert(expectedComplexType != null, "expectedComplexType != null");
            Debug.Assert(payloadComplexType != null, "payloadComplexType != null");

            // Complex types could be assignable
            if (!EdmLibraryExtensions.IsAssignableFrom(expectedComplexType, payloadComplexType))
            {
                throw new ODataException(Strings.ValidationUtils_IncompatibleType(payloadComplexType.ODataFullName(), expectedComplexType.ODataFullName()));
            }
        }
예제 #3
0
        /// <summary>
        /// Read a complex value from the reader.
        /// </summary>
        /// <param name="complexTypeReference">The type reference of the value to read (or null if no type is available).</param>
        /// <param name="payloadTypeName">The name of the type specified in the payload.</param>
        /// <param name="serializationTypeNameAnnotation">The serialization type name for the complex value (possibly null).</param>
        /// <param name="duplicatePropertyNamesChecker">The duplicate property names checker to use (cached), or null if new one should be created.</param>
        /// <param name="epmPresent">Whether any EPM mappings exist.</param>
        /// <returns>The value read from the payload.</returns>
        /// <remarks>
        /// Pre-Condition:   XmlNodeType.Element   - the element to read the value for.
        ///                  XmlNodeType.Attribute - an attribute on the element to read the value for.
        /// Post-Condition:  XmlNodeType.EndElement - the element has been read.
        ///
        /// Note that this method will not read null values, those should be handled by the caller already.
        /// </remarks>
        private ODataComplexValue ReadComplexValue(
            IEdmComplexTypeReference complexTypeReference,
            string payloadTypeName,
            SerializationTypeNameAnnotation serializationTypeNameAnnotation,
            DuplicatePropertyNamesChecker duplicatePropertyNamesChecker,
            bool epmPresent)
        {
            this.AssertXmlCondition(XmlNodeType.Element, XmlNodeType.Attribute);

            this.IncreaseRecursionDepth();

            ODataComplexValue complexValue = new ODataComplexValue();
            IEdmComplexType   complexType  = complexTypeReference == null ? null : (IEdmComplexType)complexTypeReference.Definition;

            // If we have a metadata type for the complex value, use that type name
            // otherwise use the type name from the payload (if there was any).
            complexValue.TypeName = complexType == null ? payloadTypeName : complexType.ODataFullName();
            if (serializationTypeNameAnnotation != null)
            {
                complexValue.SetAnnotation(serializationTypeNameAnnotation);
            }

            // Move to the element (so that if we were on an attribute we can test the element for being empty)
            this.XmlReader.MoveToElement();

            if (duplicatePropertyNamesChecker == null)
            {
                duplicatePropertyNamesChecker = this.CreateDuplicatePropertyNamesChecker();
            }
            else
            {
                duplicatePropertyNamesChecker.Clear();
            }

            List <ODataProperty> properties = new List <ODataProperty>();

            this.ReadPropertiesImplementation(complexType, properties, duplicatePropertyNamesChecker, epmPresent);
            complexValue.Properties = new ReadOnlyEnumerable <ODataProperty>(properties);

            this.AssertXmlCondition(true, XmlNodeType.EndElement);
            Debug.Assert(complexValue != null, "The method should never return null since it doesn't handle null values.");

            this.DecreaseRecursionDepth();

            return(complexValue);
        }
예제 #4
0
        /// <summary>
        /// Validates that the <paramref name="payloadComplexType"/> is assignable to the <paramref name="expectedComplexType"/>
        /// and fails if it's not.
        /// </summary>
        /// <param name="expectedComplexType">The expected complex type reference, the base type of the ComplexType expected.</param>
        /// <param name="payloadComplexType">The payload complex type reference to validate.</param>
        internal static void ValidateComplexTypeIsAssignable(IEdmComplexType expectedComplexType, IEdmComplexType payloadComplexType)
        {
            Debug.Assert(expectedComplexType != null, "expectedComplexType != null");
            Debug.Assert(payloadComplexType != null, "payloadComplexType != null");

            // Complex types could be assignable
            if (!EdmLibraryExtensions.IsAssignableFrom(expectedComplexType, payloadComplexType))
            {
                throw new ODataException(Strings.ValidationUtils_IncompatibleType(payloadComplexType.ODataFullName(), expectedComplexType.ODataFullName()));
            }
        }