Exemple #1
0
        /// <summary>Gets ODataProperty for the given <paramref name="property"/>.</summary>
        /// <param name="entityToSerialize">Entity that is currently being serialized.</param>
        /// <param name="property">ResourceProperty instance in question.</param>
        /// <returns>A instance of ODataProperty for the given <paramref name="property"/>.</returns>
        private ODataProperty GetODataPropertyForEntityProperty(EntityToSerialize entityToSerialize, ResourceProperty property)
        {
            Debug.Assert(entityToSerialize != null, "entityToSerialize != null");
            Debug.Assert(property != null && entityToSerialize.ResourceType.Properties.Contains(property), "property != null && currentResourceType.Properties.Contains(property)");

            ODataValue odataPropertyValue;

            if (property.IsOfKind(ResourcePropertyKind.Stream))
            {
                odataPropertyValue = this.GetNamedStreamPropertyValue(entityToSerialize, property);
            }
            else
            {
                object propertyValue = WebUtil.GetPropertyValue(this.Provider, entityToSerialize.Entity, entityToSerialize.ResourceType, property, null);
                odataPropertyValue = this.GetPropertyValue(property.Name, property.ResourceType, propertyValue, false /*openProperty*/);
            }

            ODataProperty odataProperty = new ODataProperty()
            {
                Name  = property.Name,
                Value = odataPropertyValue
            };

            ODataPropertyKind kind = property.IsOfKind(ResourcePropertyKind.Key) ? ODataPropertyKind.Key : property.IsOfKind(ResourcePropertyKind.ETag) ? ODataPropertyKind.ETag : ODataPropertyKind.Unspecified;

            if (kind != ODataPropertyKind.Unspecified)
            {
                odataProperty.SetSerializationInfo(new ODataPropertySerializationInfo {
                    PropertyKind = kind
                });
            }

            return(odataProperty);
        }
        /// <summary>
        /// Gets the property name value pairs filtered by serialization property kind.
        /// </summary>
        /// <param name="entry">The entry to get the properties from.</param>
        /// <param name="propertyKind">The serialization info property kind.</param>
        /// <param name="actualEntityTypeName">The entity type name of the entry.</param>
        /// <returns>The property name value pairs filtered by serialization property kind.</returns>
        private static KeyValuePair<string, object>[] GetPropertiesBySerializationInfoPropertyKind(ODataEntry entry, ODataPropertyKind propertyKind, string actualEntityTypeName)
        {
            Debug.Assert(entry != null, "entry != null");
            Debug.Assert(propertyKind == ODataPropertyKind.Key || propertyKind == ODataPropertyKind.ETag, "propertyKind == ODataPropertyKind.Key || propertyKind == ODataPropertyKind.ETag");

            KeyValuePair<string, object>[] properties = EmptyProperties;
            if (entry.NonComputedProperties != null)
            {
                properties = entry.NonComputedProperties.Where(p => p.SerializationInfo != null && p.SerializationInfo.PropertyKind == propertyKind).Select(p => new KeyValuePair<string, object>(p.Name, GetPrimitivePropertyClrValue(actualEntityTypeName, p, propertyKind == ODataPropertyKind.Key))).ToArray();
            }

            return properties;
        }
        /// <summary>
        /// Gets the property name value pairs filtered by serialization property kind.
        /// </summary>
        /// <param name="resource">The resource to get the properties from.</param>
        /// <param name="propertyKind">The serialization info property kind.</param>
        /// <param name="actualEntityTypeName">The entity type name of the resource.</param>
        /// <returns>The property name value pairs filtered by serialization property kind.</returns>
        private static KeyValuePair <string, object>[] GetPropertiesBySerializationInfoPropertyKind(ODataResource resource, ODataPropertyKind propertyKind, string actualEntityTypeName)
        {
            Debug.Assert(resource != null, "resource != null");
            Debug.Assert(propertyKind == ODataPropertyKind.Key || propertyKind == ODataPropertyKind.ETag, "propertyKind == ODataPropertyKind.Key || propertyKind == ODataPropertyKind.ETag");

            KeyValuePair <string, object>[] properties = EmptyProperties;
            if (resource.NonComputedProperties != null)
            {
                properties = resource.NonComputedProperties.Where(p => p.SerializationInfo != null && p.SerializationInfo.PropertyKind == propertyKind).Select(p => new KeyValuePair <string, object>(p.Name, GetPrimitiveOrEnumPropertyValue(actualEntityTypeName, p, propertyKind == ODataPropertyKind.Key))).ToArray();
            }

            return(properties);
        }
        /// <summary>
        /// Gets the property name value pairs filtered by serialization property kind.
        /// </summary>
        /// <param name="resource">The resource to get the properties from.</param>
        /// <param name="propertyKind">The serialization info property kind.</param>
        /// <param name="actualEntityTypeName">The entity type name of the resource.</param>
        /// <returns>The property name value pairs filtered by serialization property kind.</returns>
        private static KeyValuePair <string, object>[] GetPropertiesBySerializationInfoPropertyKind(ODataResourceBase resource, ODataPropertyKind propertyKind, string actualEntityTypeName)
        {
            Debug.Assert(resource != null, "resource != null");
            Debug.Assert(propertyKind == ODataPropertyKind.Key || propertyKind == ODataPropertyKind.ETag, "propertyKind == ODataPropertyKind.Key || propertyKind == ODataPropertyKind.ETag");

            List <KeyValuePair <string, object> > properties = new List <KeyValuePair <string, object> >();

            if (resource.NonComputedProperties != null)
            {
                foreach (ODataProperty property in resource.NonComputedProperties)
                {
                    if (property.SerializationInfo != null && property.SerializationInfo.PropertyKind == propertyKind)
                    {
                        properties.Add(new KeyValuePair <string, object>(property.Name, GetPrimitiveOrEnumPropertyValue(actualEntityTypeName, property, false)));
                    }
                }
            }

            return(properties.ToArray());
        }