Esempio n. 1
0
        private void EnqueueTextNode()
        {
            Debug.Assert(_accumulatedText != null, "Creating unnecessary XamlText objects");

            // Don't send the text if it is Whitespace outside the root tag.
            if (!(_scannerStack.Depth == 0 && AccumulatedText.IsWhiteSpaceOnly))
            {
                XamlScannerNode node = new XamlScannerNode(_xmlLineInfo);
                node.NodeType    = ScannerNodeType.TEXT;
                node.TextContent = AccumulatedText;
                _readNodesQueue.Enqueue(node);
            }
        }
Esempio n. 2
0
        private bool ReadObjectElement_Object(string xmlns, string name, XamlScannerNode node)
        {
            if (IsXDataElement(xmlns, name))
            {
                // If XData don't Enqueue the <x:XData> node.
                // just queue the InnerXml as TEXT (w/ IsTextXML == true).
                // This will advance the "current" xml node to the </x:XData>
                // which will be skipped when we return and the main loop
                // Read()s to the "next" XmlNode.
                ReadInnerXDataSection();
                return(true);
            }

            IList <XamlTypeName> typeArgs = null;

            if (_typeArgumentAttribute != null)
            {
                string error;
                typeArgs = XamlTypeName.ParseListInternal(_typeArgumentAttribute.Value, _parserContext.FindNamespaceByPrefix, out error);
                if (typeArgs == null)
                {
                    throw new XamlParseException(_typeArgumentAttribute.LineNumber, _typeArgumentAttribute.LinePosition, error);
                }
            }
            XamlTypeName typeName = new XamlTypeName(xmlns, name, typeArgs);

            node.Type = _parserContext.GetXamlType(typeName, true);

            // Finish initializing the attributes in the context of the
            // current Element.
            PostprocessAttributes(node);

            if (_scannerStack.Depth > 0)
            {
                // Sub-elements (and Text) are the definition of Content
                _scannerStack.CurrentlyInContent = true;
            }

            if (!node.IsEmptyTag)
            {
                node.NodeType = ScannerNodeType.ELEMENT;
                _scannerStack.Push(node.Type, node.TypeNamespace);
            }
            else
            {
                node.NodeType = ScannerNodeType.EMPTYELEMENT;
            }
            return(false);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 private void ReadObjectElement_DirectiveProperty(XamlMember dirProperty, XamlScannerNode node)
 {
     node.PropertyElement = dirProperty;
     this.PostprocessAttributes(node);
     if (this._scannerStack.Depth > 0)
     {
         this._scannerStack.CurrentlyInContent = false;
     }
     if (!node.IsEmptyTag)
     {
         this._scannerStack.CurrentProperty = node.PropertyElement;
     }
     node.NodeType            = ScannerNodeType.PROPERTYELEMENT;
     node.IsCtorForcingMember = false;
 }
Esempio n. 6
0
        private void ReadObjectElement_NoNamespace(XamlName name, XamlScannerNode node)
        {
            XamlType type = this.CreateErrorXamlType(name, string.Empty);

            node.Type = type;
            this.PostprocessAttributes(node);
            if (!node.IsEmptyTag)
            {
                node.NodeType = ScannerNodeType.ELEMENT;
                this._scannerStack.Push(node.Type, node.TypeNamespace);
            }
            else
            {
                node.NodeType = ScannerNodeType.EMPTYELEMENT;
            }
        }
Esempio n. 7
0
        private void ReadInnerXDataSection()
        {
            XamlScannerNode item = new XamlScannerNode(this._xmlLineInfo);

            this._xmlReader.MoveToContent();
            string str = this._xmlReader.ReadInnerXml().Trim();

            item.NodeType  = ScannerNodeType.TEXT;
            item.IsTextXML = true;
            XamlText text = new XamlText(true);

            text.Paste(str, false);
            item.TextContent = text;
            this._readNodesQueue.Enqueue(item);
            this.ProcessCurrentXmlNode();
        }
Esempio n. 8
0
        private void ReadEndElement()
        {
            this.EnqueueAnyText();
            if (this._scannerStack.CurrentProperty != null)
            {
                this._scannerStack.CurrentProperty    = null;
                this._scannerStack.CurrentlyInContent = false;
            }
            else
            {
                this._scannerStack.Pop();
            }
            XamlScannerNode item = new XamlScannerNode(this._xmlLineInfo)
            {
                NodeType = ScannerNodeType.ENDTAG
            };

            this._readNodesQueue.Enqueue(item);
        }
Esempio n. 9
0
        private void ReadInnerXDataSection()
        {
            XamlScannerNode node = new XamlScannerNode(_xmlLineInfo);

            _xmlReader.MoveToContent(); // skip whitespaces
            string xmlData = _xmlReader.ReadInnerXml();

            xmlData          = xmlData.Trim();
            node.NodeType    = ScannerNodeType.TEXT;
            node.IsXDataText = true;
            XamlText xmlText = new XamlText(true);

            xmlText.Paste(xmlData, false);
            node.TextContent = xmlText;
            _readNodesQueue.Enqueue(node);

            // Read InnerXml will advance over the End xData tag and
            // we need to process the current XML state w/o going back for a Read().
            ProcessCurrentXmlNode();
        }
Esempio n. 10
0
        private void ReadObjectElement_DirectiveProperty(XamlMember dirProperty, XamlScannerNode node)
        {
            node.PropertyElement = dirProperty;

            // node.Type is not set so any found attributes are and error.
            // We don't want to skip them silently.
            PostprocessAttributes(node);

            if (_scannerStack.Depth > 0)
            {
                // A property Element tag will be the end of content.
                _scannerStack.CurrentlyInContent = false;
            }

            if (!node.IsEmptyTag)
            {
                _scannerStack.CurrentProperty = node.PropertyElement;
            }
            node.NodeType            = ScannerNodeType.PROPERTYELEMENT;
            node.IsCtorForcingMember = false;
        }
Esempio n. 11
0
        private bool ReadObjectElement_Object(string xmlns, string name, XamlScannerNode node)
        {
            if (this.IsXDataElement(xmlns, name))
            {
                this.ReadInnerXDataSection();
                return(true);
            }
            IList <XamlTypeName> typeArguments = null;

            if (this._typeArgumentAttribute != null)
            {
                string str;
                typeArguments = XamlTypeName.ParseListInternal(this._typeArgumentAttribute.Value, new Func <string, string>(this._parserContext.FindNamespaceByPrefix), out str);
                if (typeArguments == null)
                {
                    throw new XamlParseException(this._typeArgumentAttribute.LineNumber, this._typeArgumentAttribute.LinePosition, str);
                }
            }
            XamlTypeName typeName = new XamlTypeName(xmlns, name, typeArguments);

            node.Type = this._parserContext.GetXamlType(typeName, true);
            this.PostprocessAttributes(node);
            if (this._scannerStack.Depth > 0)
            {
                this._scannerStack.CurrentlyInContent = true;
            }
            if (!node.IsEmptyTag)
            {
                node.NodeType = ScannerNodeType.ELEMENT;
                this._scannerStack.Push(node.Type, node.TypeNamespace);
            }
            else
            {
                node.NodeType = ScannerNodeType.EMPTYELEMENT;
            }
            return(false);
        }
Esempio n. 12
0
        private void ReadEndElement()
        {
            // Accumulated text is enqued at start of tags (element and property)
            // and at end tags.
            EnqueueAnyText();

            // if we are ending a property element tag clear the current property
            // if we are ending an element then pop off the current frame.
            if (_scannerStack.CurrentProperty != null)
            {
                _scannerStack.CurrentProperty = null;
                // List of Content is considered separately for each property.
                _scannerStack.CurrentlyInContent = false;
            }
            else
            {
                _scannerStack.Pop();
            }

            XamlScannerNode node = new XamlScannerNode(_xmlLineInfo);

            node.NodeType = ScannerNodeType.ENDTAG;
            _readNodesQueue.Enqueue(node);
        }
Esempio n. 13
0
 public void Read()
 {
     this.LoadQueue();
     this._currentNode = this._readNodesQueue.Dequeue();
 }
Esempio n. 14
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;
            }
        }
Esempio n. 15
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);
            }
        }
Esempio n. 16
0
 public void Read()
 {
     LoadQueue();
     _currentNode = _readNodesQueue.Dequeue();
 }
Esempio n. 17
0
        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);
            }
        }
Esempio n. 18
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);
                    }
                }
            }
        }
Esempio n. 19
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;
            }
        }