Пример #1
0
        public static DocumentNode ParseMarkupExtension(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, IType valueType, string text)
        {
            MarkupExtensionDescription description = MarkupExtensionParser.Tokenize(parserContext, lineInformation, text);

            if (description != null)
            {
                IType typeId1 = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespaceResolver, description.Name, true);
                if (typeId1 != null)
                {
                    if (parserContext.PlatformMetadata.KnownTypes.NullExtension.Equals((object)typeId1))
                    {
                        if (description.PositionalArguments.Count > 0 || description.NamedArguments.Count > 0)
                        {
                            parserContext.ReportError(XamlParseErrors.InvalidMarkupExtensionArguments(lineInformation, description.Name));
                        }
                        if (valueType.SupportsNullValues)
                        {
                            return((DocumentNode)parserContext.DocumentContext.CreateNode((ITypeId)valueType, (IDocumentNodeValue)null));
                        }
                        parserContext.ReportError(XamlParseErrors.TypeIsNotNullable(lineInformation, (ITypeId)valueType));
                        return((DocumentNode)null);
                    }
                    if (parserContext.PlatformMetadata.KnownTypes.TypeExtension.IsAssignableFrom((ITypeId)typeId1))
                    {
                        string extensionArgument = MarkupExtensionParser.GetRequiredMarkupExtensionArgument(parserContext, lineInformation, description, parserContext.PlatformMetadata.KnownProperties.TypeExtensionTypeName.Name);
                        if (extensionArgument != null)
                        {
                            IType typeId2 = XamlTypeHelper.GetTypeId(parserContext, lineInformation, xmlNamespaceResolver, extensionArgument, true);
                            if (typeId2 != null)
                            {
                                return((DocumentNode)parserContext.DocumentContext.CreateNode(parserContext.PlatformMetadata.KnownTypes.Type, (IDocumentNodeValue) new DocumentNodeMemberValue((IMember)typeId2)));
                            }
                        }
                    }
                    else if (parserContext.PlatformMetadata.KnownTypes.StaticExtension.IsAssignableFrom((ITypeId)typeId1))
                    {
                        string extensionArgument = MarkupExtensionParser.GetRequiredMarkupExtensionArgument(parserContext, lineInformation, description, parserContext.PlatformMetadata.KnownProperties.StaticExtensionMember.Name);
                        if (extensionArgument != null)
                        {
                            IType  typeId2;
                            string memberName;
                            if (MarkupExtensionParser.GetTypeAndMemberName(parserContext, lineInformation, xmlNamespaceResolver, extensionArgument, (IType)null, out typeId2, out memberName))
                            {
                                MemberAccessTypes allowableMemberAccess = TypeHelper.GetAllowableMemberAccess(parserContext.TypeResolver, typeId2);
                                MemberType        memberTypes           = MemberType.LocalProperty | MemberType.Field;
                                if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions))
                                {
                                    memberTypes |= MemberType.IncompleteAttachedProperty;
                                }
                                IMember memberId = (IMember)typeId2.GetMember(memberTypes, memberName, allowableMemberAccess) ?? XamlTypeHelper.AddMemberIfPossible(parserContext.PlatformMetadata, typeId2, MemberType.LocalProperty, memberName);
                                if (memberId != null)
                                {
                                    return((DocumentNode)DocumentNodeHelper.NewStaticNode(parserContext.DocumentContext, memberId));
                                }
                                parserContext.ReportError(XamlParseErrors.UnrecognizedOrInaccessibleMember(lineInformation, memberName));
                            }
                            return((DocumentNode)null);
                        }
                    }
                    else
                    {
                        if (!parserContext.TypeResolver.PlatformMetadata.KnownTypes.Binding.Equals((object)typeId1) || description.PositionalArguments.Count != 1)
                        {
                            return(MarkupExtensionParser.ParseMarkupExtension(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, typeId1, description));
                        }
                        description.NamedArguments.Insert(0, new KeyValuePair <string, string>(parserContext.TypeResolver.PlatformMetadata.KnownProperties.BindingPath.Name, description.PositionalArguments[0]));
                        description.PositionalArguments.Clear();
                        return(MarkupExtensionParser.ParseMarkupExtension(parserContext, lineInformation, nodeReference, xmlNamespaceResolver, typeId1, description));
                    }
                }
            }
            return((DocumentNode)null);
        }