Ejemplo n.º 1
0
        /// <summary>
        /// Returns a resource type of the property on the specified resource type.
        /// </summary>
        /// <param name="resourceType">The resource type to look for the property on.</param>
        /// <param name="propertyName">The name of the property to look for.</param>
        /// <param name="isMultiValueProperty">return true if the property was a MultiValue property.</param>
        /// <returns>The type of the property specified. Note that for MultiValue properties this returns the type of the item of the MultiValue property.</returns>
        private static ResourceType GetPropertyType(ResourceType resourceType, string propertyName, out bool isMultiValueProperty)
        {
            Debug.Assert(propertyName != null, "propertyName != null");

            isMultiValueProperty = false;
            ResourceProperty resourceProperty = resourceType != null ? resourceType.TryResolvePropertyName(propertyName) : null;

            if (resourceProperty != null)
            {
                if (resourceProperty.IsOfKind(ResourcePropertyKind.MultiValue))
                {
                    isMultiValueProperty = true;
                    Debug.Assert(resourceProperty.ResourceType is MultiValueResourceType, "MultiValue property must be of the MultiValueResourceType.");
                    MultiValueResourceType multiValueResourceType = (MultiValueResourceType)resourceProperty.ResourceType;
                    return multiValueResourceType.ItemType;
                }
                else
                {
                    return resourceProperty.ResourceType;
                }
            }
            else
            {
                if (resourceType != null && !resourceType.IsOpenType)
                {
                    // could be a named stream
                    resourceProperty = resourceType.TryResolveNamedStream(propertyName);
                    if (resourceProperty != null)
                    {
                        throw new ODataException(Strings.EpmSourceTree_NamedStreamCannotBeMapped(propertyName, resourceType.FullName));
                    }
                    else
                    {
                        throw new ODataException(Strings.EpmSourceTree_MissingPropertyOnType(propertyName, resourceType.FullName));
                    }
                }

                return null;
            }
        }