protected void ApplyProperty(ODataProperty property, ResourceType resourceType, object resource)
        {
            ResourceType     type;
            string           name             = property.Name;
            ResourceProperty resourceProperty = resourceType.TryResolvePropertyName(name);

            if (resourceProperty == null)
            {
                type = null;
            }
            else
            {
                if (resourceProperty.Kind == ResourcePropertyKind.Stream)
                {
                    return;
                }
                if (base.Update && resourceProperty.IsOfKind(ResourcePropertyKind.Key))
                {
                    return;
                }
                type = resourceProperty.ResourceType;
            }
            object propertyValue = this.ConvertValue(property.Value, ref type);

            if (resourceProperty == null)
            {
                Deserializer.SetOpenPropertyValue(resource, name, propertyValue, base.Service);
            }
            else
            {
                Deserializer.SetPropertyValue(resourceProperty, resource, propertyValue, base.Service);
            }
        }
예제 #2
0
        /// <summary>Applies a property from the reader to the specified resource.</summary>
        /// <param name='reader'>XmlReader to read from.</param>
        /// <param name='propertyName'>Name of property to set on the specified resource.</param>
        /// <param name='resourceType'>Type of resource.</param>
        /// <param name='resource'>Resource to set value on.</param>
        private void ApplyProperty(XmlReader reader, string propertyName, ResourceType resourceType, object resource)
        {
            Debug.Assert(reader != null, "reader != null");
            Debug.Assert(propertyName != null, "propertyName != null");
            Debug.Assert(resourceType != null, "resourceType != null");
            Debug.Assert(resource != null, "resource != null");

            ResourceProperty property    = resourceType.TryResolvePropertyName(propertyName);
            bool             ignoreValue = false;

            if (property == null)
            {
                if (resourceType.IsOpenType == false)
                {
                    throw DataServiceException.CreateBadRequestError(Strings.BadRequest_InvalidPropertyNameSpecified(propertyName, resourceType.FullName));
                }
            }
            else
            {
                if (this.Update && property.IsOfKind(ResourcePropertyKind.Key))
                {
                    ignoreValue = true;
                }
            }

            object propertyValue = this.ReadPropertyWithType(reader, propertyName, property);

            if (!ignoreValue)
            {
                if (property == null)
                {
                    Deserializer.SetOpenPropertyValue(resource, propertyName, propertyValue, this.Service);
                }
                else
                {
                    Deserializer.SetPropertyValue(property, resource, propertyValue, this.ContentFormat, this.Service);
                }
            }
        }