Ejemplo n.º 1
0
        private static object ReadPropertyValue(object element, ClientType resourceType, string[] srcPathSegments, int currentSegment)
        {
            if (element == null || currentSegment == srcPathSegments.Length)
            {
                return(element);
            }
            else
            {
                String srcPathPart = srcPathSegments[currentSegment];

                ClientType.ClientProperty resourceProperty = resourceType.GetProperty(srcPathPart, true);
                if (resourceProperty == null)
                {
                    throw Error.InvalidOperation(Strings.EpmSourceTree_InaccessiblePropertyOnType(srcPathPart, resourceType.ElementTypeName));
                }

                if (resourceProperty.IsKnownType ^ (currentSegment == srcPathSegments.Length - 1))
                {
                    throw Error.InvalidOperation(!resourceProperty.IsKnownType ? Strings.EpmClientType_PropertyIsComplex(resourceProperty.PropertyName) :
                                                 Strings.EpmClientType_PropertyIsPrimitive(resourceProperty.PropertyName));
                }

                PropertyInfo pi = element.GetType().GetProperty(srcPathPart, BindingFlags.Instance | BindingFlags.Public);
                Debug.Assert(pi != null, "Cannot find property " + srcPathPart + "on type " + element.GetType().Name);

                return(ReadPropertyValue(
                           pi.GetValue(element, null),
                           resourceProperty.IsKnownType ? null : ClientType.Create(resourceProperty.PropertyType),
                           srcPathSegments,
                           ++currentSegment));
            }
        }
        /// <summary>Checks whether a given property can be a complex property i.e. implements INotifyPropertyChanged.</summary>
        /// <param name="property">Input property.</param>
        /// <returns>true if the property is complex property, false otherwise.</returns>
        private static bool CanBeComplexProperty(ClientType.ClientProperty property)
        {
            Debug.Assert(property != null, "property != null");
            if (typeof(INotifyPropertyChanged).IsAssignableFrom(property.PropertyType))
            {
                Debug.Assert(!property.IsKnownType, "Known types do not implement INotifyPropertyChanged.");
                return(true);
            }

            return(false);
        }