Exemplo n.º 1
0
        public static ReferenceStep GetProperty(ITypeResolver typeResolver, Type type, MemberType propertyType, string name)
        {
            PlatformTypes platformMetadata = (PlatformTypes)typeResolver.PlatformMetadata;

            return((ReferenceStep)platformMetadata.GetProperty(typeResolver, type, propertyType, name));
        }
Exemplo n.º 2
0
        private static PropertyReference ResolvePropertyPathParts(ITypeResolver typeResolver, string path, Collection <object> parameters, SceneNode pathRoot)
        {
            if (path == "(0)")
            {
                if (parameters == null || parameters.Count == 0)
                {
                    return((PropertyReference)null);
                }
                DependencyProperty dependencyProperty = parameters[0] as DependencyProperty;
                if (dependencyProperty == null)
                {
                    return((PropertyReference)null);
                }
                Type targetType = pathRoot != null ? pathRoot.TargetType : dependencyProperty.OwnerType;
                DependencyPropertyReferenceStep referenceStep = DependencyPropertyReferenceStep.GetReferenceStep(typeResolver, targetType, dependencyProperty);
                if (referenceStep == null)
                {
                    return((PropertyReference)null);
                }
                return(new PropertyReference((ReferenceStep)referenceStep));
            }
            List <ReferenceStep> list = new List <ReferenceStep>();
            object obj = (object)null;

            if (typeResolver.IsCapabilitySet(PlatformCapability.SupportTypelessPropertyPath) && pathRoot != null && pathRoot.IsViewObjectValid)
            {
                obj = pathRoot.ViewObject.PlatformSpecificObject;
            }
            IType typeId = obj == null ? (pathRoot == null ? (parameters == null || parameters.Count <= 0 || !(parameters[0] is DependencyProperty) ? typeResolver.ResolveType(PlatformTypes.Object) : typeResolver.GetType(((DependencyProperty)parameters[0]).OwnerType)) : pathRoot.Type) : typeResolver.GetType(obj.GetType());

            for (int index1 = 0; index1 < path.Length; ++index1)
            {
                ReferenceStep referenceStep = (ReferenceStep)null;
                char          ch            = path[index1];
                switch (ch)
                {
                case '(':
                    int num1 = path.IndexOf(')', index1 + 1);
                    if (num1 < 0)
                    {
                        return((PropertyReference)null);
                    }
                    string s = path.Substring(index1 + 1, num1 - index1 - 1);
                    int    result1;
                    if (int.TryParse(s, out result1))
                    {
                        if (parameters == null || result1 < 0 || result1 >= parameters.Count)
                        {
                            return((PropertyReference)null);
                        }
                        DependencyProperty dependencyProperty = parameters[result1] as DependencyProperty;
                        if (dependencyProperty == null)
                        {
                            return((PropertyReference)null);
                        }
                        referenceStep = (ReferenceStep)DependencyPropertyReferenceStep.GetReferenceStep(typeResolver, typeId.NearestResolvedType.RuntimeType, dependencyProperty);
                        if (referenceStep == null)
                        {
                            PlatformTypes platformTypes = (PlatformTypes)typeResolver.PlatformMetadata;
                            Type          runtimeType   = typeId.NearestResolvedType.RuntimeType;
                            Type          ownerType     = dependencyProperty.OwnerType;
                            referenceStep = (ReferenceStep)(platformTypes.GetProperty(typeResolver, ownerType, MemberType.LocalProperty, dependencyProperty.Name) as DependencyPropertyReferenceStep);
                            if (referenceStep == null || !runtimeType.IsAssignableFrom(ownerType))
                            {
                                return((PropertyReference)null);
                            }
                        }
                    }
                    else
                    {
                        int    length = s.IndexOf('.');
                        string typeName;
                        if (length < 0)
                        {
                            if (!typeResolver.IsCapabilitySet(PlatformCapability.SupportTypelessPropertyPath))
                            {
                                return((PropertyReference)null);
                            }
                            typeName = typeId.Name;
                            length   = -1;
                        }
                        else
                        {
                            typeName = s.Substring(0, length);
                        }
                        string str = s.Substring(length + 1);
                        if (string.IsNullOrEmpty(typeName))
                        {
                            return((PropertyReference)null);
                        }
                        IType type = typeResolver.GetType((IXmlNamespace)typeResolver.GetCapabilityValue(PlatformCapability.DefaultXmlns), typeName);
                        if (type == null)
                        {
                            IProperty designTimeProperty = typeResolver.PlatformMetadata.GetDesignTimeProperty(str, (IType)null);
                            if (designTimeProperty != null && designTimeProperty.DeclaringType.Name == typeName)
                            {
                                referenceStep = (ReferenceStep)designTimeProperty;
                            }
                        }
                        if (referenceStep == null)
                        {
                            if (type == null)
                            {
                                type = typeId;
                            }
                            referenceStep = type.GetMember(MemberType.Property, str, MemberAccessTypes.Public) as ReferenceStep ?? TimelineSceneNode.ResolveReferenceStepFromValue(typeResolver, pathRoot, list, str);
                        }
                        if (referenceStep == null)
                        {
                            return((PropertyReference)null);
                        }
                    }
                    index1 = num1;
                    break;

                case '[':
                    int num2 = path.IndexOf(']', index1 + 1);
                    if (num2 < 0)
                    {
                        return((PropertyReference)null);
                    }
                    int result2;
                    if (!int.TryParse(path.Substring(index1 + 1, num2 - index1 - 1), out result2))
                    {
                        return((PropertyReference)null);
                    }
                    referenceStep = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep(typeResolver, typeId.RuntimeType, result2, false);
                    index1        = num2;
                    if (referenceStep == null)
                    {
                        return((PropertyReference)null);
                    }
                    break;

                default:
                    int startIndex = index1;
                    if ((int)ch == 46)
                    {
                        ++startIndex;
                    }
                    if (index1 >= path.Length - 1)
                    {
                        return((PropertyReference)null);
                    }
                    int index2 = index1 + 1;
                    if ((int)path[index2] != 40)
                    {
                        for (; index2 < path.Length; ++index2)
                        {
                            switch (path[index2])
                            {
                            case '.':
                            case '[':
                                goto label_52;

                            default:
                                goto default;
                            }
                        }
label_52:
                        if (index1 >= index2 - 1)
                        {
                            return((PropertyReference)null);
                        }
                        string str = path.Substring(startIndex, index2 - startIndex);
                        referenceStep = typeId.GetMember(MemberType.LocalProperty | MemberType.Field, str, TypeHelper.GetAllowableMemberAccess(typeResolver, typeId)) as ReferenceStep;
                        if (referenceStep == null)
                        {
                            referenceStep = TimelineSceneNode.ResolveReferenceStepFromValue(typeResolver, pathRoot, list, str);
                            if (referenceStep == null)
                            {
                                return((PropertyReference)null);
                            }
                        }
                        index1 = index2 - 1;
                        break;
                    }
                    break;
                }
                if (referenceStep != null)
                {
                    list.Add(referenceStep);
                    typeId = referenceStep.PropertyType;
                }
            }
            if (list == null || list.Count <= 0)
            {
                return((PropertyReference)null);
            }
            return(new PropertyReference(list));
        }