コード例 #1
0
ファイル: MeScanner.cs プロジェクト: redmcg/wpf
        private void ResolvePropertyName(string longName)
        {
            XamlPropertyName propName = XamlPropertyName.Parse(longName);

            if (propName == null)
            {
                throw new ArgumentException(SR.Get(SRID.MalformedPropertyName));
            }

            XamlMember prop = null;
            XamlType   declaringType;
            XamlType   tagType      = _context.CurrentType;
            string     tagNamespace = _context.CurrentTypeNamespace;

            if (propName.IsDotted)
            {
                prop = _context.GetDottedProperty(tagType, tagNamespace, propName, false /*tagIsRoot*/);
            }
            // Regular property p
            else
            {
                string ns = _context.GetAttributeNamespace(propName, Namespace);
                declaringType = _context.CurrentType;
                prop          = _context.GetNoDotAttributeProperty(declaringType, propName, Namespace, ns, false /*tagIsRoot*/);
            }
            _tokenProperty = prop;
        }
コード例 #2
0
ファイル: XamlPropertyName.cs プロジェクト: zx597855313/wpf
        public static XamlPropertyName Parse(string longName, string namespaceURI)
        {
            XamlPropertyName propName = Parse(longName);

            propName._namespace = namespaceURI;
            return(propName);
        }
コード例 #3
0
        private void ReadPropertyElement(XamlPropertyName name, XamlType tagType, string tagNamespace, bool isEmptyTag)
        {
            XamlScannerNode node = new XamlScannerNode(this._xmlLineInfo);

            this.PreprocessAttributes();
            string     namespaceURI = this._xmlReader.NamespaceURI;
            XamlMember member       = null;
            bool       tagIsRoot    = this._scannerStack.Depth == 1;

            member             = this._parserContext.GetDottedProperty(tagType, tagNamespace, name, tagIsRoot);
            node.Prefix        = name.Prefix;
            node.TypeNamespace = namespaceURI;
            node.IsEmptyTag    = isEmptyTag;
            this.PostprocessAttributes(node);
            if (this._scannerStack.Depth > 0)
            {
                this._scannerStack.CurrentlyInContent = false;
            }
            node.PropertyElement     = member;
            node.IsCtorForcingMember = !member.IsAttachable;
            if (!node.IsEmptyTag)
            {
                this._scannerStack.CurrentProperty = node.PropertyElement;
                node.NodeType = ScannerNodeType.PROPERTYELEMENT;
            }
            else
            {
                node.NodeType = ScannerNodeType.EMPTYPROPERTYELEMENT;
            }
            this._readNodesQueue.Enqueue(node);
            while (this.HaveUnprocessedAttributes)
            {
                this.EnqueueAnotherAttribute(isEmptyTag);
            }
        }
コード例 #4
0
 private void PreprocessAttributes()
 {
     if (this._xmlReader.MoveToFirstAttribute())
     {
         List <XamlAttribute> attrList = new List <XamlAttribute>();
         do
         {
             string           longName = this._xmlReader.Name;
             string           val      = this._xmlReader.Value;
             XamlPropertyName propName = XamlPropertyName.Parse(longName);
             if (propName == null)
             {
                 throw new XamlParseException(System.Xaml.SR.Get("InvalidXamlMemberName", new object[] { longName }));
             }
             XamlAttribute attr = new XamlAttribute(propName, val, this._xmlLineInfo);
             if (attr.Kind == ScannerAttributeKind.Namespace)
             {
                 this.EnqueuePrefixDefinition(attr);
             }
             else
             {
                 attrList.Add(attr);
             }
         }while (this._xmlReader.MoveToNextAttribute());
         this.PreprocessForTypeArguments(attrList);
         if (attrList.Count > 0)
         {
             this._attributes = attrList;
         }
         this._xmlReader.MoveToElement();
     }
 }
コード例 #5
0
ファイル: XamlScanner.cs プロジェクト: xhowar/lindexi_gd
        // ============= Element Processing ==================================

        private void ReadElement()
        {
            // Accumulated text is enqueued a piece of content before this element
            EnqueueAnyText();
            _hasKeyAttribute = false;
            // Empty Elements are by definition leaf elements and they
            // don't nest.  So we don't need to stack this state.
            bool isEmptyTag = _xmlReader.IsEmptyElement;

            string prefix       = _xmlReader.Prefix;
            string strippedName = _xmlReader.LocalName;

            if (XamlName.ContainsDot(strippedName))
            {
                Debug.Assert(_xmlReader.NodeType == XmlNodeType.Element);
                XamlPropertyName name = XamlPropertyName.Parse(_xmlReader.Name, _xmlReader.NamespaceURI);
                if (_scannerStack.CurrentType == null)
                {
                    throw LineInfo(new XamlParseException(SR.Get(SRID.ParentlessPropertyElement, _xmlReader.Name)));
                }
                ReadPropertyElement(name, _scannerStack.CurrentType, _scannerStack.CurrentTypeNamespace, isEmptyTag);
            }
            else
            {
                XamlName name = new XamlQualifiedName(prefix, strippedName);
                ReadObjectElement(name, isEmptyTag);
            }
        }
コード例 #6
0
        //  ========================== private ================================

        private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName,
                                                    XamlType tagType, string tagNamespace, bool tagIsRoot)
        {
            XamlMember prop = null;
            string     ns   = context.GetAttributeNamespace(propName, tagNamespace);

            // No Namespace, == Unknown Property
            if (ns == null)
            {
                XamlMember unknownProperty;
                if (propName.IsDotted)
                {
                    XamlType attachedOwnerType = new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext);
                    unknownProperty = new XamlMember(propName.Name, attachedOwnerType, true /*isAttachable*/);
                }
                else
                {
                    unknownProperty = new XamlMember(propName.Name, tagType, false);
                }
                return(unknownProperty);
            }

            // Get the property (attached, normal, or directive)
            if (propName.IsDotted)
            {
                prop = context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot);
            }
            else
            {
                prop = context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, ns, tagIsRoot);
            }

            return(prop);
        }
コード例 #7
0
 public string GetAttributeNamespace(XamlPropertyName propName, string tagNamespace)
 {
     if (string.IsNullOrEmpty(propName.Prefix) && !propName.IsDotted)
     {
         return tagNamespace;
     }
     return this.ResolveXamlNameNS(propName);
 }
コード例 #8
0
 public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot)
 {
     if (tagType == null)
     {
         throw new XamlInternalException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { propName.ScopedName }));
     }
     XamlMember xamlAttachableProperty = null;
     XamlType xamlType = null;
     string propNs = this.ResolveXamlNameNS(propName);
     if (propNs == null)
     {
         throw new XamlParseException(System.Xaml.SR.Get("PrefixNotFound", new object[] { propName.Prefix }));
     }
     XamlType rootTagType = tagIsRoot ? tagType : null;
     bool flag = false;
     if (tagType.IsGeneric)
     {
         flag = this.PropertyTypeMatchesGenericTagType(tagType, tagNamespace, propNs, propName.OwnerName);
         if (flag)
         {
             xamlAttachableProperty = this.GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType);
             if (xamlAttachableProperty != null)
             {
                 return xamlAttachableProperty;
             }
         }
     }
     XamlTypeName typeName = new XamlTypeName(propNs, propName.Owner.Name);
     xamlType = this.GetXamlType(typeName, true);
     bool flag2 = tagType.CanAssignTo(xamlType);
     if (flag2)
     {
         xamlAttachableProperty = this.GetInstanceOrAttachableProperty(xamlType, propName.Name, rootTagType);
     }
     else
     {
         xamlAttachableProperty = this.GetXamlAttachableProperty(xamlType, propName.Name);
     }
     if (xamlAttachableProperty != null)
     {
         return xamlAttachableProperty;
     }
     XamlType declaringType = flag ? tagType : xamlType;
     if (flag || flag2)
     {
         return this.CreateUnknownMember(declaringType, propName.Name);
     }
     return this.CreateUnknownAttachableMember(declaringType, propName.Name);
 }
コード例 #9
0
 public XamlAttribute(XamlPropertyName propName, string val, IXmlLineInfo lineInfo)
 {
     this.Name  = propName;
     this.Value = val;
     this.Kind  = ScannerAttributeKind.Property;
     if (lineInfo != null)
     {
         this.LineNumber   = lineInfo.LineNumber;
         this.LinePosition = lineInfo.LinePosition;
     }
     if (this.CheckIsXmlNamespaceDefinition(out this._xmlnsDefinitionPrefix, out this._xmlnsDefinitionUri))
     {
         this.Kind = ScannerAttributeKind.Namespace;
     }
 }
コード例 #10
0
 public XamlAttribute(XamlPropertyName propName, string val, IXmlLineInfo lineInfo)
 {
     this.Name = propName;
     this.Value = val;
     this.Kind = ScannerAttributeKind.Property;
     if (lineInfo != null)
     {
         this.LineNumber = lineInfo.LineNumber;
         this.LinePosition = lineInfo.LinePosition;
     }
     if (this.CheckIsXmlNamespaceDefinition(out this._xmlnsDefinitionPrefix, out this._xmlnsDefinitionUri))
     {
         this.Kind = ScannerAttributeKind.Namespace;
     }
 }
コード例 #11
0
ファイル: XamlScanner.cs プロジェクト: xhowar/lindexi_gd
        // ======== Attribute Processing =============================

        private void PreprocessAttributes()
        {
            // Collect up all the attributes.
            bool b = _xmlReader.MoveToFirstAttribute();

            if (!b)
            {
                return;
            }

            List <XamlAttribute> list = new List <XamlAttribute>();

            do
            {
                string xmlName = _xmlReader.Name;
                string val     = _xmlReader.Value;

                XamlPropertyName propName = XamlPropertyName.Parse(xmlName);

                if (propName == null)
                {
                    throw new XamlParseException(SR.Get(SRID.InvalidXamlMemberName, xmlName));
                }

                XamlAttribute attr = new XamlAttribute(propName, val, _xmlLineInfo);

                if (attr.Kind == ScannerAttributeKind.Namespace)
                {
                    EnqueuePrefixDefinition(attr);
                }
                else
                {
                    list.Add(attr);
                }

                b = _xmlReader.MoveToNextAttribute();
            } while (b);

            PreprocessForTypeArguments(list);

            if (list.Count > 0)
            {
                _attributes = list;
            }
            // Restore the XML reader’s position to the Element after reading the
            // attributes so that the rest of the code can always assume it is on an Element
            _xmlReader.MoveToElement();
        }
コード例 #12
0
        public XamlAttribute(XamlPropertyName propName, string val, IXmlLineInfo lineInfo)
        {
            Name  = propName;
            Value = val;
            Kind  = ScannerAttributeKind.Property; // non-"namespace" default;
            if (lineInfo != null)
            {
                LineNumber   = lineInfo.LineNumber;
                LinePosition = lineInfo.LinePosition;
            }

            // XmlNs like:   xmlns:c="someUristring"
            if (CheckIsXmlNamespaceDefinition(out _xmlnsDefinitionPrefix, out _xmlnsDefinitionUri))
            {
                Kind = ScannerAttributeKind.Namespace;
            }
        }
コード例 #13
0
 private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName, XamlType tagType, string tagNamespace, bool tagIsRoot)
 {
     string attributeNamespace = context.GetAttributeNamespace(propName, tagNamespace);
     if (attributeNamespace == null)
     {
         if (propName.IsDotted)
         {
             return new XamlMember(propName.Name, new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext), true);
         }
         return new XamlMember(propName.Name, tagType, false);
     }
     if (propName.IsDotted)
     {
         return context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot);
     }
     return context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, attributeNamespace, tagIsRoot);
 }
コード例 #14
0
ファイル: XamlPropertyName.cs プロジェクト: zx597855313/wpf
        public static XamlPropertyName Parse(string longName)
        {
            if (String.IsNullOrEmpty(longName))
            {
                return(null);
            }

            string prefix;
            string dottedName;

            if (!XamlQualifiedName.Parse(longName, out prefix, out dottedName))
            {
                return(null);
            }

            int    start = 0;
            string owner = string.Empty;

            int dotIdx = dottedName.IndexOf('.');

            if (dotIdx != -1)
            {
                owner = dottedName.Substring(start, dotIdx);

                if (String.IsNullOrEmpty(owner))
                {
                    return(null);
                }

                start = dotIdx + 1;
            }

            string name = (start == 0) ? dottedName : dottedName.Substring(start);

            XamlQualifiedName ownerName = null;

            if (!String.IsNullOrEmpty(owner))
            {
                ownerName = new XamlQualifiedName(prefix, owner);
            }

            XamlPropertyName propName = new XamlPropertyName(ownerName, prefix, name);

            return(propName);
        }
コード例 #15
0
        private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName, XamlType tagType, string tagNamespace, bool tagIsRoot)
        {
            string attributeNamespace = context.GetAttributeNamespace(propName, tagNamespace);

            if (attributeNamespace == null)
            {
                if (propName.IsDotted)
                {
                    return(new XamlMember(propName.Name, new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext), true));
                }
                return(new XamlMember(propName.Name, tagType, false));
            }
            if (propName.IsDotted)
            {
                return(context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot));
            }
            return(context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, attributeNamespace, tagIsRoot));
        }
コード例 #16
0
        private void ReadElement()
        {
            this.EnqueueAnyText();
            this._hasKeyAttribute = false;
            bool   isEmptyElement = this._xmlReader.IsEmptyElement;
            string prefix         = this._xmlReader.Prefix;
            string localName      = this._xmlReader.LocalName;

            if (XamlName.ContainsDot(localName))
            {
                XamlPropertyName name = XamlPropertyName.Parse(this._xmlReader.Name, this._xmlReader.NamespaceURI);
                if (this._scannerStack.CurrentType == null)
                {
                    throw this.LineInfo(new XamlParseException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { this._xmlReader.Name })));
                }
                this.ReadPropertyElement(name, this._scannerStack.CurrentType, this._scannerStack.CurrentTypeNamespace, isEmptyElement);
            }
            else
            {
                XamlName name2 = new XamlQualifiedName(prefix, localName);
                this.ReadObjectElement(name2, isEmptyElement);
            }
        }
コード例 #17
0
        private void ResolvePropertyName(string longName)
        {
            XamlPropertyName propName = XamlPropertyName.Parse(longName);

            if (propName == null)
            {
                throw new ArgumentException(System.Xaml.SR.Get("MalformedPropertyName"));
            }
            XamlMember member               = null;
            XamlType   currentType          = this._context.CurrentType;
            string     currentTypeNamespace = this._context.CurrentTypeNamespace;

            if (propName.IsDotted)
            {
                member = this._context.GetDottedProperty(currentType, currentTypeNamespace, propName, false);
            }
            else
            {
                string   attributeNamespace = this._context.GetAttributeNamespace(propName, this._tokenNamespace);
                XamlType tagType            = this._context.CurrentType;
                member = this._context.GetNoDotAttributeProperty(tagType, propName, this._tokenNamespace, attributeNamespace, false);
            }
            this._tokenProperty = member;
        }
コード例 #18
0
 private void ReadPropertyElement(XamlPropertyName name, XamlType tagType, string tagNamespace, bool isEmptyTag)
 {
     XamlScannerNode node = new XamlScannerNode(this._xmlLineInfo);
     this.PreprocessAttributes();
     string namespaceURI = this._xmlReader.NamespaceURI;
     XamlMember member = null;
     bool tagIsRoot = this._scannerStack.Depth == 1;
     member = this._parserContext.GetDottedProperty(tagType, tagNamespace, name, tagIsRoot);
     node.Prefix = name.Prefix;
     node.TypeNamespace = namespaceURI;
     node.IsEmptyTag = isEmptyTag;
     this.PostprocessAttributes(node);
     if (this._scannerStack.Depth > 0)
     {
         this._scannerStack.CurrentlyInContent = false;
     }
     node.PropertyElement = member;
     node.IsCtorForcingMember = !member.IsAttachable;
     if (!node.IsEmptyTag)
     {
         this._scannerStack.CurrentProperty = node.PropertyElement;
         node.NodeType = ScannerNodeType.PROPERTYELEMENT;
     }
     else
     {
         node.NodeType = ScannerNodeType.EMPTYPROPERTYELEMENT;
     }
     this._readNodesQueue.Enqueue(node);
     while (this.HaveUnprocessedAttributes)
     {
         this.EnqueueAnotherAttribute(isEmptyTag);
     }
 }
コード例 #19
0
ファイル: XamlScanner.cs プロジェクト: xhowar/lindexi_gd
        private void ReadPropertyElement(XamlPropertyName name, XamlType tagType, string tagNamespace, bool isEmptyTag)
        {
            // <Button>   <== currentElement
            //   <FrameworkElement.Width>   <== FrameworkElement is ownerType

            XamlScannerNode node = new XamlScannerNode(_xmlLineInfo);

            // Attributes aren't allowed on property elements.
            // but if they are there we need to scan them so the
            // XamlParser can error, or whatever.
            // (don't want to skip them w/o error)
            PreprocessAttributes();

            // It is possible for an application to provide XML nodes via XmlNodeReader
            // where the URI is defined but there was no xmlns attribute for use to resolve against.
            // See app Paperboy
            Debug.Assert(_xmlReader.NodeType == XmlNodeType.Element);
            string     ownerNamespace = _xmlReader.NamespaceURI;
            XamlMember property       = null;

            bool tagIsRoot = _scannerStack.Depth == 1; // PEs are processed after frame is pushed

            property = _parserContext.GetDottedProperty(tagType, tagNamespace, name, tagIsRoot);

            node.Prefix        = name.Prefix;
            node.TypeNamespace = ownerNamespace;
            node.IsEmptyTag    = isEmptyTag;

            // node.Type is not set (this is a property)
            // so this processing does less.
            PostprocessAttributes(node);

            if (_scannerStack.Depth > 0)
            {
                // A property Element tag will be the end of content.
                // This also allows to to start content again.
                // That is an error, but at least the parser/scanner can
                // understand what is going on.
                _scannerStack.CurrentlyInContent = false;
            }

            node.PropertyElement = property;

            node.IsCtorForcingMember = !property.IsAttachable;

            if (!node.IsEmptyTag)
            {
                _scannerStack.CurrentProperty = node.PropertyElement;
                node.NodeType = ScannerNodeType.PROPERTYELEMENT;
            }
            else
            {
                node.NodeType = ScannerNodeType.EMPTYPROPERTYELEMENT;
            }

            _readNodesQueue.Enqueue(node);

            while (HaveUnprocessedAttributes)
            {
                EnqueueAnotherAttribute(isEmptyTag);
            }
        }
コード例 #20
0
 public XamlMember GetNoDotAttributeProperty(XamlType tagType, XamlPropertyName propName, string tagNamespace, string propUsageNamespace, bool tagIsRoot)
 {
     XamlMember xamlAttachableProperty = null;
     if ((propUsageNamespace == tagNamespace) || (((tagNamespace == null) && (propUsageNamespace != null)) && tagType.GetXamlNamespaces().Contains(propUsageNamespace)))
     {
         XamlType rootObjectType = tagIsRoot ? tagType : null;
         xamlAttachableProperty = this.GetXamlProperty(tagType, propName.Name, rootObjectType);
         if (xamlAttachableProperty == null)
         {
             xamlAttachableProperty = this.GetXamlAttachableProperty(tagType, propName.Name);
         }
     }
     if ((xamlAttachableProperty == null) && (propUsageNamespace != null))
     {
         XamlDirective xamlDirective = this.SchemaContext.GetXamlDirective(propUsageNamespace, propName.Name);
         if (xamlDirective != null)
         {
             if ((xamlDirective.AllowedLocation & AllowedMemberLocations.Attribute) == AllowedMemberLocations.None)
             {
                 xamlDirective = new XamlDirective(propUsageNamespace, propName.Name);
             }
             xamlAttachableProperty = xamlDirective;
         }
     }
     if (xamlAttachableProperty != null)
     {
         return xamlAttachableProperty;
     }
     if (tagNamespace == propUsageNamespace)
     {
         return new XamlMember(propName.Name, tagType, false);
     }
     return new XamlDirective(propUsageNamespace, propName.Name);
 }