コード例 #1
0
        private static DocumentNode ParseMarkupExtension(XamlParserContext parserContext, ITextLocation lineInformation, IDocumentNodeReference nodeReference, IXmlNamespaceResolver xmlNamespaceResolver, IType typeId, MarkupExtensionDescription description)
        {
            int count = description.PositionalArguments.Count;
            DocumentCompositeNode  node = parserContext.DocumentContext.CreateNode((ITypeId)typeId);
            IDocumentNodeReference documentNodeReference = (IDocumentNodeReference) new DocumentCompositeNodeReference(nodeReference, node);
            IConstructor           constructor1          = (IConstructor)null;

            if (typeId.IsResolvable)
            {
                IList <IConstructor> constructors = typeId.GetConstructors();
                if (constructors.Count > 0)
                {
                    int num = 0;
                    foreach (IConstructor constructor2 in (IEnumerable <IConstructor>)constructors)
                    {
                        if (constructor2.Parameters.Count == count)
                        {
                            if (num == 0)
                            {
                                constructor1 = constructor2;
                            }
                            ++num;
                        }
                    }
                    if (num == 0)
                    {
                        parserContext.ReportError(XamlParseErrors.IncorrectNumberOfConstructorArguments(lineInformation, (ITypeId)typeId));
                    }
                    else if (num <= 1)
                    {
                        ;
                    }
                }
                else
                {
                    parserContext.ReportError(XamlParseErrors.NoAccessibleConstructor(lineInformation, (ITypeId)typeId));
                }
            }
            DocumentNode[] documentNodeArray = constructor1 != null ? new DocumentNode[constructor1.Parameters.Count] : (DocumentNode[])null;
            IConstructorArgumentProperties argumentProperties = typeId.GetConstructorArgumentProperties();

            if (count > 0)
            {
                for (int index = 0; index < count; ++index)
                {
                    string str  = description.PositionalArguments[index];
                    bool   flag = constructor1 != null && index < constructor1.Parameters.Count;
                    IType  type = parserContext.TypeResolver.ResolveType(parserContext.TypeResolver.PlatformMetadata.KnownTypes.Object);
                    if (flag)
                    {
                        IParameter parameter = constructor1.Parameters[index];
                        type = parserContext.TypeResolver.ResolveType((ITypeId)parameter.ParameterType);
                        IProperty property = argumentProperties[parameter.Name];
                        if (property != null && !property.PropertyType.IsAssignableFrom((ITypeId)type))
                        {
                            flag = false;
                            parserContext.ReportError(XamlParseErrors.ConstructorArgumentDeclaredTypeDoesNotMatchProperty(lineInformation, (IPropertyId)property));
                        }
                    }
                    TypeConverter typeConverter = type.TypeConverter;
                    DocumentNode  propertyValue = MarkupExtensionParser.GetPropertyValue(parserContext, lineInformation, documentNodeReference, xmlNamespaceResolver, typeConverter, type, str, true);
                    if (flag && propertyValue != null)
                    {
                        documentNodeArray[index] = XamlParser.CanAssignTo(parserContext, lineInformation, type, propertyValue) ? propertyValue : (DocumentNode)null;
                    }
                }
            }
            node.SetConstructor(constructor1, (IList <DocumentNode>)documentNodeArray);
            int num1 = 0;

            foreach (KeyValuePair <string, string> keyValuePair in (IEnumerable <KeyValuePair <string, string> >)description.NamedArguments)
            {
                string     key         = keyValuePair.Key;
                MemberType memberTypes = MemberType.LocalProperty | MemberType.AttachedProperty | MemberType.Field;
                if (parserContext.TypeResolver.IsCapabilitySet(PlatformCapability.IncompleteAttachedPropertiesInMarkupExtensions))
                {
                    memberTypes |= MemberType.IncompleteAttachedProperty;
                }
                IProperty propertyKey = XamlTypeHelper.GetPropertyKey(parserContext, lineInformation, xmlNamespaceResolver, key, (XmlNamespace)null, typeId, memberTypes, MemberType.LocalProperty, false);
                if (propertyKey != null)
                {
                    DocumentNode propertyValue = MarkupExtensionParser.GetPropertyValue(parserContext, lineInformation, documentNodeReference, xmlNamespaceResolver, propertyKey, keyValuePair.Value, true);
                    if (propertyValue != null && XamlParser.SetProperty(parserContext, lineInformation, new DocumentCompositeNodeReference(documentNodeReference, node), (XamlSourceContext)null, (IPropertyId)propertyKey, propertyValue))
                    {
                        propertyValue.ContainerSourceContext = (INodeSourceContext) new MarkupExtensionParser.MinimalSourceContext(num1++);
                    }
                }
            }
            return((DocumentNode)node);
        }