예제 #1
0
 /// <summary>
 /// Creates instance of EntityPropertyMappingInfo class.
 /// </summary>
 /// <param name="attribute">The <see cref="EntityPropertyMappingAttribute"/> corresponding to this object</param>
 /// <param name="definingType">Type the <see cref="EntityPropertyMappingAttribute"/> was defined on.</param>
 /// <param name="actualPropertyType">Type whose property is to be read. This can be different from defining type when inheritance is involved.</param>
 /// <param name="isEFProvider">Whether the current data source is an EF provider. Needed for error reporting.</param>
 public EntityPropertyMappingInfo(EntityPropertyMappingAttribute attribute, ResourceType definingType, ResourceType actualPropertyType, bool isEFProvider)
 {
     this.isEFProvider = isEFProvider;
예제 #2
0
        /// <summary>
        /// Given a source property path in the segmented form reads the property value from the resource type instance.
        /// </summary>
        /// <param name="element">Resource type instance.</param>
        /// <param name="provider">Underlying data provider.</param>
        /// <param name="resourceType">Resource type whose property is to be read.</param>
        /// <param name="srcPathSegments">Segmented source property path.</param>
        /// <param name="currentSegment">Index of current property name in <paramref name="srcPathSegments"/></param>
        /// <returns>Property value read from the resource type instance. Possibly null.</returns>
        private static object ReadPropertyValue(object element, DataServiceProviderWrapper provider, ResourceType resourceType, string[] srcPathSegments, int currentSegment)
        {
            if (element == null || currentSegment == srcPathSegments.Length)
            {
                return element;
            }
            else
            {
                String propertyName = srcPathSegments[currentSegment];
                ResourceProperty resourceProperty = resourceType != null ? resourceType.TryResolvePropertyName(propertyName) : null;

                if (resourceProperty != null)
                {
                    // If this is the last part of the path, then it has to be a primitive type otherwise should be a complex type
                    if (!resourceProperty.IsOfKind(currentSegment == srcPathSegments.Length - 1 ? ResourcePropertyKind.Primitive : ResourcePropertyKind.ComplexType))
                    {
                        throw new InvalidOperationException(Strings.EpmSourceTree_EndsWithNonPrimitiveType(propertyName));
                    }
                }
                else
                {
                    if (!(resourceType == null || resourceType.IsOpenType))
                    {
                        throw new InvalidOperationException(Strings.EpmSourceTree_InaccessiblePropertyOnType(propertyName, resourceType.Name));
                    }

                    // this is an open type resolve resourceType and try resolving resourceProperty
                    resourceType = WebUtil.GetNonPrimitiveResourceType(provider, element);
                    resourceProperty = resourceType.TryResolvePropertyName(propertyName);
                }

                Debug.Assert(resourceType != null, "resourceType != null");
                object propertyValue = WebUtil.GetPropertyValue(provider, element, resourceType, resourceProperty, resourceProperty == null ? propertyName : null);

                return ReadPropertyValue(
                    propertyValue,
                    provider,
                    resourceProperty != null ? resourceProperty.ResourceType : null,
                    srcPathSegments,
                    currentSegment + 1);
            }
        }