示例#1
0
        private void PreprocessForTypeArguments(List <XamlAttribute> attrList)
        {
            int typeArgsIdx = -1;

            for (int i = 0; i < attrList.Count; i++)
            {
                XamlAttribute attr = attrList[i];

                // Find x:TypeArguments if it was present.
                if (KS.Eq(attr.Name.Name, XamlLanguage.TypeArguments.Name))
                {
                    string     attrNamespace     = _parserContext.FindNamespaceByPrefix(attr.Name.Prefix);
                    XamlMember directiveProperty = _parserContext.ResolveDirectiveProperty(attrNamespace, attr.Name.Name);
                    if (directiveProperty != null)
                    {
                        typeArgsIdx            = i;
                        _typeArgumentAttribute = attr;
                        break;
                    }
                }
            }
            if (typeArgsIdx >= 0)
            {
                attrList.RemoveAt(typeArgsIdx);
            }
        }
示例#2
0
        private void ReadObjectElement(XamlName name, bool isEmptyTag)
        {
            this._typeArgumentAttribute = null;
            XamlScannerNode node = new XamlScannerNode(this._xmlLineInfo);

            this.PreprocessAttributes();
            node.Prefix     = name.Prefix;
            node.IsEmptyTag = isEmptyTag;
            string namespaceURI = this._xmlReader.NamespaceURI;

            if (namespaceURI == null)
            {
                this.ReadObjectElement_NoNamespace(name, node);
            }
            else
            {
                node.TypeNamespace = namespaceURI;
                XamlMember xamlDirective = this._parserContext.SchemaContext.GetXamlDirective(namespaceURI, name.Name);
                if (xamlDirective != null)
                {
                    this.ReadObjectElement_DirectiveProperty(xamlDirective, node);
                }
                else if (this.ReadObjectElement_Object(namespaceURI, name.Name, node))
                {
                    return;
                }
            }
            this._readNodesQueue.Enqueue(node);
            while (this.HaveUnprocessedAttributes)
            {
                this.EnqueueAnotherAttribute(isEmptyTag);
            }
        }
示例#3
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();
     }
 }
示例#4
0
        // ReadObjectElement: reads the entire start tag.  This may result in
        // more than one Scanner Nodes.   The results are enqueued onto a list
        // rather than returned directly, then the caller can de-queue the nodes
        // one at a time.
        private void ReadObjectElement(XamlName name, bool isEmptyTag)
        {
            _typeArgumentAttribute = null;
            XamlScannerNode node = new XamlScannerNode(_xmlLineInfo);

            // Scan for xmlns(s) before attempting to resolve the type.
            // So while we are there, collect up all the attributes.
            // Enqueue the xmlns attributes first.
            // PostProcess and Enqueue the other attributes after.
            PreprocessAttributes();

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

            // 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 xamlNs = _xmlReader.NamespaceURI;

            if (xamlNs == null)
            {
                ReadObjectElement_NoNamespace(name, node);
            }
            else  // if (xamlNs != null)
            {
                node.TypeNamespace = xamlNs;

                // First check if the XML element is a
                // Directive Property  <x:Key>
                //
                XamlSchemaContext schemaContext = _parserContext.SchemaContext;
                XamlMember        dirProperty   = schemaContext.GetXamlDirective(xamlNs, name.Name);
                if (dirProperty != null)
                {
                    ReadObjectElement_DirectiveProperty(dirProperty, node);
                }
                else  // normal Element Case.
                {
                    bool sawXData = ReadObjectElement_Object(xamlNs, name.Name, node);
                    if (sawXData)
                    {
                        return;
                    }
                }
            }

            _readNodesQueue.Enqueue(node);

            // Now add the processed attributes from the rest of the start tag.
            while (HaveUnprocessedAttributes)
            {
                EnqueueAnotherAttribute(isEmptyTag);
            }
        }
示例#5
0
        private void EnqueuePrefixDefinition(XamlAttribute attr)
        {
            string prefix        = attr.XmlNsPrefixDefined;
            string xamlNamespace = attr.XmlNsUriDefined;

            _parserContext.AddNamespacePrefix(prefix, xamlNamespace);

            XamlScannerNode node = new XamlScannerNode(attr);

            node.NodeType      = ScannerNodeType.PREFIXDEFINITION;
            node.Prefix        = prefix;
            node.TypeNamespace = xamlNamespace;

            _readNodesQueue.Enqueue(node);
        }
示例#6
0
        private void EnqueuePrefixDefinition(XamlAttribute attr)
        {
            string xmlNsPrefixDefined = attr.XmlNsPrefixDefined;
            string xmlNsUriDefined    = attr.XmlNsUriDefined;

            this._parserContext.AddNamespacePrefix(xmlNsPrefixDefined, xmlNsUriDefined);
            XamlScannerNode item = new XamlScannerNode(attr)
            {
                NodeType      = ScannerNodeType.PREFIXDEFINITION,
                Prefix        = xmlNsPrefixDefined,
                TypeNamespace = xmlNsUriDefined
            };

            this._readNodesQueue.Enqueue(item);
        }
示例#7
0
        // ======== 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();
        }
示例#8
0
        private void PreprocessForTypeArguments(List <XamlAttribute> attrList)
        {
            int index = -1;

            for (int i = 0; i < attrList.Count; i++)
            {
                XamlAttribute attribute = attrList[i];
                if (KS.Eq(attribute.Name.Name, XamlLanguage.TypeArguments.Name))
                {
                    string xamlNS = this._parserContext.FindNamespaceByPrefix(attribute.Name.Prefix);
                    if (this._parserContext.ResolveDirectiveProperty(xamlNS, attribute.Name.Name) != null)
                    {
                        index = i;
                        this._typeArgumentAttribute = attribute;
                        break;
                    }
                }
            }
            if (index >= 0)
            {
                attrList.RemoveAt(index);
            }
        }
示例#9
0
        private void EnqueueAnotherAttribute(bool isEmptyTag)
        {
            XamlAttribute   attr = _attributes[_nextAttribute++];
            XamlScannerNode node = new XamlScannerNode(attr);

            switch (attr.Kind)
            {
            case ScannerAttributeKind.Directive:
            case ScannerAttributeKind.Name:
            case ScannerAttributeKind.CtorDirective:
                node.NodeType = ScannerNodeType.DIRECTIVE;
                break;

            case ScannerAttributeKind.XmlSpace:
                // Empty tags don't have a stack frame to write on.
                // Empty XML tags don't have content to process spaces.
                if (!isEmptyTag)
                {
                    if (KS.Eq(attr.Value, KnownStrings.Preserve))
                    {
                        _scannerStack.CurrentXmlSpacePreserve = true;
                    }
                    else
                    {
                        _scannerStack.CurrentXmlSpacePreserve = false;
                    }
                }
                node.NodeType = ScannerNodeType.DIRECTIVE;
                break;

            case ScannerAttributeKind.Event:
            case ScannerAttributeKind.Property:
                node.IsCtorForcingMember = true;
                node.NodeType            = ScannerNodeType.ATTRIBUTE;
                break;

            case ScannerAttributeKind.Unknown:
                XamlMember prop = attr.Property;
                Debug.Assert(prop.IsUnknown);
                // force use of Ctor for unknown simple properties only
                node.IsCtorForcingMember = !prop.IsAttachable && !prop.IsDirective;
                node.NodeType            = ScannerNodeType.ATTRIBUTE;
                break;

            case ScannerAttributeKind.AttachableProperty:
                node.NodeType = ScannerNodeType.ATTRIBUTE;
                break;

            default:
                throw new XamlInternalException(SR.Get(SRID.AttributeUnhandledKind));
            }

            // (GetFixedDocumentSequence raises Exception "UnicodeString property does not
            // contain enough characters to correspond to the contents of Indices property.")
            //
            // XamlText.Paste normally converts CRLF to LF, even in attribute values.
            // When the property is Glyphs.UnicodeString, disable this;
            // the length of the string must correspond to the number of entries in
            // the corresponding Glyphs.Indices property.
            XamlMember attrProperty    = attr.Property;
            bool       convertCRLFtoLF =
                !(attrProperty != null &&
                  attrProperty.Name == "UnicodeString" &&
                  attrProperty.DeclaringType.Name == "Glyphs");

            node.PropertyAttribute = attrProperty;
            XamlText xamlText = new XamlText(true);  // Don't collapse spaces in attributes

            xamlText.Paste(attr.Value, false, convertCRLFtoLF);
            node.PropertyAttributeText = xamlText;
            node.Prefix = attr.Name.Prefix;

            _readNodesQueue.Enqueue(node);

            if (_nextAttribute >= _attributes.Count)
            {
                _attributes    = null;
                _nextAttribute = -1;
            }
        }
示例#10
0
        private void PostprocessAttributes(XamlScannerNode node)
        {
            if (_attributes == null)
            {
                return;
            }

            _nextAttribute = 0;

            // Attributes on Properties are errors
            // and don't need this detailed processing.
            if (node.Type == null)
            {
                if (_settings.IgnoreUidsOnPropertyElements)
                {
                    StripUidProperty();
                }
                return;
            }


            bool tagIsRoot = _scannerStack.Depth == 0; // Attributes are processed before frame is pushed

            foreach (XamlAttribute attr in _attributes)
            {
                attr.Initialize(_parserContext, node.Type, node.TypeNamespace, tagIsRoot);
            }

            // Sort the Attributes into the order the XAML parser likes.

            List <XamlAttribute> ctorDirectivesList  = null;
            List <XamlAttribute> otherDirectivesList = null;
            List <XamlAttribute> otherPropertiesList = null;
            XamlAttribute        nameAttribute       = null;

            // The Name attribute
            foreach (XamlAttribute attr in _attributes)
            {
                switch (attr.Kind)
                {
                case ScannerAttributeKind.Name:
                    nameAttribute = attr;
                    break;

                case ScannerAttributeKind.CtorDirective:
                    if (ctorDirectivesList == null)
                    {
                        ctorDirectivesList = new List <XamlAttribute>();
                    }
                    ctorDirectivesList.Add(attr);
                    break;

                case ScannerAttributeKind.Directive:
                case ScannerAttributeKind.XmlSpace:
                    if (attr.Property == XamlLanguage.Key)
                    {
                        _hasKeyAttribute = true;
                    }

                    if (otherDirectivesList == null)
                    {
                        otherDirectivesList = new List <XamlAttribute>();
                    }
                    otherDirectivesList.Add(attr);
                    break;

                default:
                    if (otherPropertiesList == null)
                    {
                        otherPropertiesList = new List <XamlAttribute>();
                    }
                    otherPropertiesList.Add(attr);
                    break;
                }
            }

            _attributes = new List <XamlAttribute>();

            // First the Construction Directives
            if (ctorDirectivesList != null)
            {
                _attributes.AddRange(ctorDirectivesList);
            }

            if (otherDirectivesList != null)
            {
                _attributes.AddRange(otherDirectivesList);
            }

            // Next the aliased Name property before any other "real" properties.
            // (this is a WPF template requirement)
            if (nameAttribute != null)
            {
                _attributes.Add(nameAttribute);
            }

            // Then everything else
            if (otherPropertiesList != null)
            {
                _attributes.AddRange(otherPropertiesList);
            }
        }
示例#11
0
 public XamlScannerNode(XamlAttribute attr)
 {
     LineNumber   = attr.LineNumber;
     LinePosition = attr.LinePosition;
 }
示例#12
0
        private void EnqueueAnotherAttribute(bool isEmptyTag)
        {
            XamlAttribute   attr = this._attributes[this._nextAttribute++];
            XamlScannerNode item = new XamlScannerNode(attr);

            switch (attr.Kind)
            {
            case ScannerAttributeKind.CtorDirective:
            case ScannerAttributeKind.Name:
            case ScannerAttributeKind.Directive:
                item.NodeType = ScannerNodeType.DIRECTIVE;
                goto Label_00F3;

            case ScannerAttributeKind.XmlSpace:
                if (!isEmptyTag)
                {
                    if (!KS.Eq(attr.Value, "preserve"))
                    {
                        this._scannerStack.CurrentXmlSpacePreserve = false;
                        break;
                    }
                    this._scannerStack.CurrentXmlSpacePreserve = true;
                }
                break;

            case ScannerAttributeKind.Event:
            case ScannerAttributeKind.Property:
                item.IsCtorForcingMember = true;
                item.NodeType            = ScannerNodeType.ATTRIBUTE;
                goto Label_00F3;

            case ScannerAttributeKind.AttachableProperty:
                item.NodeType = ScannerNodeType.ATTRIBUTE;
                goto Label_00F3;

            case ScannerAttributeKind.Unknown:
            {
                XamlMember property = attr.Property;
                item.IsCtorForcingMember = !property.IsAttachable && !property.IsDirective;
                item.NodeType            = ScannerNodeType.ATTRIBUTE;
                goto Label_00F3;
            }

            default:
                throw new XamlInternalException(System.Xaml.SR.Get("AttributeUnhandledKind"));
            }
            item.NodeType = ScannerNodeType.DIRECTIVE;
Label_00F3:
            item.PropertyAttribute = attr.Property;
            XamlText text = new XamlText(true);

            text.Paste(attr.Value, false);
            item.PropertyAttributeText = text;
            item.Prefix = attr.Name.Prefix;
            this._readNodesQueue.Enqueue(item);
            if (this._nextAttribute >= this._attributes.Count)
            {
                this._attributes    = null;
                this._nextAttribute = -1;
            }
        }
示例#13
0
        private void PostprocessAttributes(XamlScannerNode node)
        {
            if (this._attributes != null)
            {
                this._nextAttribute = 0;
                if (node.Type == null)
                {
                    if (this._settings.IgnoreUidsOnPropertyElements)
                    {
                        this.StripUidProperty();
                    }
                }
                else
                {
                    bool tagIsRoot = this._scannerStack.Depth == 0;
                    foreach (XamlAttribute attribute in this._attributes)
                    {
                        attribute.Initialize(this._parserContext, node.Type, node.TypeNamespace, tagIsRoot);
                    }
                    List <XamlAttribute> collection = null;
                    List <XamlAttribute> list2      = null;
                    List <XamlAttribute> list3      = null;
                    XamlAttribute        item       = null;
                    foreach (XamlAttribute attribute3 in this._attributes)
                    {
                        switch (attribute3.Kind)
                        {
                        case ScannerAttributeKind.CtorDirective:
                            if (collection == null)
                            {
                                collection = new List <XamlAttribute>();
                            }
                            collection.Add(attribute3);
                            break;

                        case ScannerAttributeKind.Name:
                            item = attribute3;
                            break;

                        case ScannerAttributeKind.Directive:
                        case ScannerAttributeKind.XmlSpace:
                            if (attribute3.Property == XamlLanguage.Key)
                            {
                                this._hasKeyAttribute = true;
                            }
                            if (list2 == null)
                            {
                                list2 = new List <XamlAttribute>();
                            }
                            list2.Add(attribute3);
                            break;

                        default:
                            if (list3 == null)
                            {
                                list3 = new List <XamlAttribute>();
                            }
                            list3.Add(attribute3);
                            break;
                        }
                    }
                    this._attributes = new List <XamlAttribute>();
                    if (collection != null)
                    {
                        this._attributes.AddRange(collection);
                    }
                    if (list2 != null)
                    {
                        this._attributes.AddRange(list2);
                    }
                    if (item != null)
                    {
                        this._attributes.Add(item);
                    }
                    if (list3 != null)
                    {
                        this._attributes.AddRange(list3);
                    }
                }
            }
        }