Exemple #1
0
        public static bool GetTypeAndMemberName(XamlParserContext parserContext, ITextLocation lineInformation, IXmlNamespaceResolver xmlNamespaceResolver, string fullMemberName, IType targetTypeId, out IType typeId, out string memberName)
        {
            typeId     = (IType)null;
            memberName = (string)null;
            XmlnsPrefix prefix;
            string      typeName1;

            if (XamlTypeHelper.SplitTypeName(parserContext, lineInformation, fullMemberName, out prefix, out typeName1))
            {
                XmlNamespace xmlNamespace = parserContext.GetXmlNamespace(lineInformation, xmlNamespaceResolver, prefix);
                string       typeName2;
                if (XamlTypeHelper.SplitMemberName(parserContext, lineInformation, typeName1, out typeName2, out memberName))
                {
                    typeId = typeName2 == null ? targetTypeId : XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespace, typeName2);
                    if (typeId != null)
                    {
                        return(true);
                    }
                    parserContext.ReportError(XamlParseErrors.CannotDetermineMemberTargetType(lineInformation, memberName));
                }
            }
            return(false);
        }
Exemple #2
0
        internal static IProperty GetPropertyKey(XamlParserContext parserContext, ITextLocation lineInformation, XmlNamespace xmlNamespace, string typeAndPropertyName, XmlNamespace targetTypeNamespace, IType targetTypeId, MemberType memberTypes, MemberType defaultType, bool allowProtectedPropertiesOnTargetType)
        {
            string typeName;
            string memberName;

            if (XamlTypeHelper.SplitMemberName(parserContext, lineInformation, typeAndPropertyName, out typeName, out memberName))
            {
                if (string.IsNullOrEmpty(memberName))
                {
                    parserContext.ReportError(XamlParseErrors.MissingArgumentName(lineInformation));
                    return((IProperty)null);
                }
                if (xmlNamespace == XmlNamespace.DesignTimeXmlNamespace)
                {
                    return(parserContext.PlatformMetadata.GetDesignTimeProperty(memberName, targetTypeId));
                }
                if (xmlNamespace != null && typeName == null)
                {
                    if (xmlNamespace == XmlNamespace.XamlXmlNamespace)
                    {
                        IProperty property = XamlProcessingAttributes.GetProperty(memberName, parserContext.TypeResolver.PlatformMetadata);
                        if (property != null)
                        {
                            return(property);
                        }
                        parserContext.ReportError(XamlParseErrors.UnrecognizedAttribute(lineInformation, xmlNamespace, memberName));
                        return((IProperty)null);
                    }
                    if (xmlNamespace == XmlNamespace.PresentationOptionsXmlNamespace)
                    {
                        if (memberName == parserContext.PlatformMetadata.KnownProperties.DesignTimeFreeze.Name)
                        {
                            return(parserContext.TypeResolver.ResolveProperty(parserContext.PlatformMetadata.KnownProperties.DesignTimeFreeze));
                        }
                        parserContext.ReportError(XamlParseErrors.UnrecognizedAttribute(lineInformation, xmlNamespace, memberName));
                        return((IProperty)null);
                    }
                    if (targetTypeNamespace == null || !xmlNamespace.Equals((object)targetTypeNamespace))
                    {
                        parserContext.ReportError(XamlParseErrors.UnrecognizedAttribute(lineInformation, xmlNamespace, memberName));
                        return((IProperty)null);
                    }
                }
                MemberAccessTypes access = MemberAccessTypes.None;
                if (typeName != null)
                {
                    if (xmlNamespace != null)
                    {
                        targetTypeId = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespace, typeName);
                        if (parserContext.PlatformMetadata.IsNullType((ITypeId)targetTypeId))
                        {
                            return((IProperty)null);
                        }
                        access = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, targetTypeId);
                    }
                }
                else if (!parserContext.PlatformMetadata.IsNullType((ITypeId)targetTypeId))
                {
                    access = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, targetTypeId);
                    if (allowProtectedPropertiesOnTargetType)
                    {
                        access |= MemberAccessTypes.Protected;
                    }
                }
                if (!parserContext.PlatformMetadata.IsNullType((ITypeId)targetTypeId))
                {
                    IProperty property1 = (IProperty)targetTypeId.GetMember(defaultType, memberName, access);
                    if (property1 == null)
                    {
                        MemberType memberTypes1 = memberTypes & ~defaultType;
                        if (memberTypes1 != MemberType.None)
                        {
                            property1 = (IProperty)targetTypeId.GetMember(memberTypes1, memberName, access);
                        }
                    }
                    if (property1 == null && targetTypeId.PlatformMetadata.GetProxyProperties(parserContext.TypeResolver) != null)
                    {
                        foreach (IProperty property2 in targetTypeId.PlatformMetadata.GetProxyProperties(parserContext.TypeResolver))
                        {
                            if (memberName == property2.Name && property2.DeclaringType.IsAssignableFrom((ITypeId)targetTypeId) && TypeHelper.IsSet(memberTypes, property2.MemberType))
                            {
                                property1 = property2;
                                break;
                            }
                        }
                    }
                    if (property1 == null)
                    {
                        property1 = (IProperty)XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, targetTypeId, defaultType, memberName);
                    }
                    if (property1 == null)
                    {
                        parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName));
                    }
                    return(property1);
                }
                parserContext.ReportError(XamlParseErrors.CannotDetermineMemberTargetType(lineInformation, memberName));
            }
            return((IProperty)null);
        }
Exemple #3
0
 public static DocumentNode CreateNodeFromTextValue(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, TypeConverter typeConverter, ITypeId valueTypeId, string value)
 {
     if (parserContext.PlatformMetadata.KnownTypes.DependencyProperty.IsAssignableFrom(valueTypeId))
     {
         MemberType memberTypes = MemberType.Property | MemberType.Field;
         if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions))
         {
             memberTypes |= MemberType.IncompleteAttachedProperty;
         }
         MemberType defaultType = value.IndexOf('.') >= 0 ? MemberType.AttachedProperty : MemberType.LocalProperty;
         IProperty  propertyKey = XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespaceResolver, value, (XmlNamespace)null, nodeReference.TargetType, memberTypes, defaultType, false);
         if (propertyKey == null)
         {
             return((DocumentNode)null);
         }
         MarkupExtensionParser.VerifyMemberIsDependencyProperty(parserContext, lineInformation, (IMember)propertyKey);
         return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)propertyKey)));
     }
     if (parserContext.PlatformMetadata.KnownTypes.ICommand.IsAssignableFrom(valueTypeId))
     {
         bool flag = typeConverter != null && !parserContext.PlatformMetadata.KnownTypes.CommandConverter.Equals((object)parserContext.TypeResolver.GetType(typeConverter.GetType()));
         if (value.IndexOf('.') < 0 || flag)
         {
             return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(value)));
         }
         IType  typeId;
         string memberName;
         if (MarkupExtensionParser.GetTypeAndMemberName(parserContext, lineInformation, xmlNamespaceResolver, value, (IType)null, out typeId, out memberName))
         {
             MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, typeId);
             IMember           member = (IMember)typeId.GetMember(MemberType.LocalProperty | MemberType.Field, memberName, allowableMemberAccess) ?? XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, typeId, MemberType.LocalProperty, memberName);
             if (member != null)
             {
                 return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue(member)));
             }
             parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName));
         }
         return((DocumentNode)null);
     }
     if (parserContext.PlatformMetadata.KnownTypes.RoutedEvent.IsAssignableFrom(valueTypeId))
     {
         IType  typeId;
         string memberName;
         if (!MarkupExtensionParser.GetTypeAndMemberName(parserContext, lineInformation, xmlNamespaceResolver, value, nodeReference.TargetType, out typeId, out memberName))
         {
             return((DocumentNode)null);
         }
         MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, typeId);
         IMember           member = (IMember)typeId.GetMember(MemberType.Event, memberName, allowableMemberAccess);
         if (member != null)
         {
             MarkupExtensionParser.VerifyMemberIsRoutedEvent(parserContext, lineInformation, member);
         }
         else
         {
             member = XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, typeId, MemberType.RoutedEvent, memberName);
         }
         if (member != null)
         {
             return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue(member)));
         }
         parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName));
         return((DocumentNode)null);
     }
     if (parserContext.PlatformMetadata.KnownTypes.Delegate.IsAssignableFrom(valueTypeId))
     {
         string memberName = value;
         if (parserContext.RootClassAttributes == null && parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IsWpf))
         {
             parserContext.ReportError(XamlParseErrors.CannotDetermineMemberTargetType(lineInformation, memberName));
         }
         return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(memberName)));
     }
     if (parserContext.PlatformMetadata.KnownTypes.PropertyPath.IsAssignableFrom(valueTypeId))
     {
         return(MarkupExtensionParser.ParsePropertyPath(parserContext, lineInformation, xmlNamespaceResolver, value));
     }
     if (parserContext.PlatformMetadata.KnownTypes.Uri.IsAssignableFrom(valueTypeId))
     {
         return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(value)));
     }
     if (parserContext.PlatformMetadata.KnownTypes.Type.IsAssignableFrom(valueTypeId))
     {
         IType typeId = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespaceResolver, value, false);
         if (typeId != null)
         {
             return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)typeId)));
         }
         return((DocumentNode)null);
     }
     if (valueTypeId.Equals((object)parserContext.TypeResolver.PlatformMetadata.KnownTypes.Object))
     {
         valueTypeId = (ITypeId)parserContext.TypeResolver.ResolveType(parserContext.TypeResolver.PlatformMetadata.KnownTypes.String);
     }
     if (valueTypeId.IsResolvable && valueTypeId != parserContext.TypeResolver.ResolveType(parserContext.TypeResolver.PlatformMetadata.KnownTypes.String) && (typeConverter == null || !typeConverter.CanConvertFrom(typeof(string))))
     {
         parserContext.ReportError(XamlParseErrors.CannotConvertFromString(lineInformation, valueTypeId));
     }
     return((DocumentNode)parserContext.DocumentContext.CreateNode(valueTypeId, (IDocumentNodeValue) new DocumentNodeStringValue(value)));
 }