Example #1
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);
            }
        }
Example #2
0
        // ============= 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);
            }
        }
Example #3
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);
            }
        }
 private XamlPropertyName(XamlName owner, string prefix, string name) : base(name)
 {
     if (owner != null)
     {
         this.Owner   = owner;
         base._prefix = owner.Prefix ?? string.Empty;
     }
     else
     {
         base._prefix = prefix ?? string.Empty;
     }
 }
 private XamlPropertyName(XamlName owner, string prefix, string name) : base(name)
 {
     if (owner != null)
     {
         this.Owner = owner;
         base._prefix = owner.Prefix ?? string.Empty;
     }
     else
     {
         base._prefix = prefix ?? string.Empty;
     }
 }
        private void State_InName()
        {
            if (IsAtEndOfInput || IsWhitespaceChar(CurrentChar) || CurrentChar == OpenBracket)
            {
                _token = GenericTypeNameScannerToken.NAME;
                _state = State.START;
                return;
            }

            switch (CurrentChar)
            {
            case OpenParen:
                _pushedBackSymbol = GenericTypeNameScannerToken.OPEN;
                _token            = GenericTypeNameScannerToken.NAME;
                _state            = State.START;
                break;

            case CloseParen:
                _pushedBackSymbol = GenericTypeNameScannerToken.CLOSE;
                _token            = GenericTypeNameScannerToken.NAME;
                _state            = State.START;
                break;

            case Comma:
                _pushedBackSymbol = GenericTypeNameScannerToken.COMMA;
                _token            = GenericTypeNameScannerToken.NAME;
                _state            = State.START;
                break;

            case Colon:
                _pushedBackSymbol = GenericTypeNameScannerToken.COLON;
                _token            = GenericTypeNameScannerToken.NAME;
                _state            = State.START;
                break;

            default:
                if (XamlName.IsValidQualifiedNameChar(CurrentChar))
                {
                    AddToMultiCharToken();
                    // No _token set so continue to scan.
                }
                else
                {
                    _token = GenericTypeNameScannerToken.ERROR;
                }
                break;
            }
            _lastChar = CurrentChar;
            Advance();
        }
        private void State_InName()
        {
            if ((base.IsAtEndOfInput || Sample_StringParserBase.IsWhitespaceChar(base.CurrentChar)) || (base.CurrentChar == '['))
            {
                this._token = GenericTypeNameScannerToken.NAME;
                this._state = State.START;
            }
            else
            {
                switch (base.CurrentChar)
                {
                case '(':
                    this._pushedBackSymbol = GenericTypeNameScannerToken.OPEN;
                    this._token            = GenericTypeNameScannerToken.NAME;
                    this._state            = State.START;
                    break;

                case ')':
                    this._pushedBackSymbol = GenericTypeNameScannerToken.CLOSE;
                    this._token            = GenericTypeNameScannerToken.NAME;
                    this._state            = State.START;
                    break;

                case ',':
                    this._pushedBackSymbol = GenericTypeNameScannerToken.COMMA;
                    this._token            = GenericTypeNameScannerToken.NAME;
                    this._state            = State.START;
                    break;

                case ':':
                    this._pushedBackSymbol = GenericTypeNameScannerToken.COLON;
                    this._token            = GenericTypeNameScannerToken.NAME;
                    this._state            = State.START;
                    break;

                default:
                    if (XamlName.IsValidQualifiedNameChar(base.CurrentChar))
                    {
                        this.AddToMultiCharToken();
                    }
                    else
                    {
                        this._token = GenericTypeNameScannerToken.ERROR;
                    }
                    break;
                }
                this._lastChar = base.CurrentChar;
                base.Advance();
            }
        }
        private void State_Start()
        {
            AdvanceOverWhitespace();
            if (IsAtEndOfInput)
            {
                _token = GenericTypeNameScannerToken.NONE;
                return;
            }

            switch (CurrentChar)
            {
            case OpenParen:
                _token = GenericTypeNameScannerToken.OPEN;
                break;

            case CloseParen:
                _token = GenericTypeNameScannerToken.CLOSE;
                break;

            case Comma:
                _token = GenericTypeNameScannerToken.COMMA;
                break;

            case Colon:
                _token = GenericTypeNameScannerToken.COLON;
                break;

            case OpenBracket:
                StartMultiCharToken();
                _state = State.INSUBSCRIPT;
                // No _token set so continue to scan.
                break;

            default:
                if (XamlName.IsValidNameStartChar(CurrentChar))
                {
                    StartMultiCharToken();
                    _state = State.INNAME;
                    // No _token set so continue to scan.
                }
                else
                {
                    _token = GenericTypeNameScannerToken.ERROR;
                }
                break;
            }
            _lastChar = CurrentChar;
            Advance();
        }
        private void State_Start()
        {
            base.AdvanceOverWhitespace();
            if (base.IsAtEndOfInput)
            {
                this._token = GenericTypeNameScannerToken.NONE;
            }
            else
            {
                switch (base.CurrentChar)
                {
                case '(':
                    this._token = GenericTypeNameScannerToken.OPEN;
                    break;

                case ')':
                    this._token = GenericTypeNameScannerToken.CLOSE;
                    break;

                case ',':
                    this._token = GenericTypeNameScannerToken.COMMA;
                    break;

                case ':':
                    this._token = GenericTypeNameScannerToken.COLON;
                    break;

                case '[':
                    this.StartMultiCharToken();
                    this._state = State.INSUBSCRIPT;
                    break;

                default:
                    if (XamlName.IsValidNameStartChar(base.CurrentChar))
                    {
                        this.StartMultiCharToken();
                        this._state = State.INNAME;
                    }
                    else
                    {
                        this._token = GenericTypeNameScannerToken.ERROR;
                    }
                    break;
                }
                this._lastChar = base.CurrentChar;
                base.Advance();
            }
        }
Example #10
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;
            }
        }
 internal static bool IsNameValid_WithPlus(string name)
 {
     if (name.Length == 0)
     {
         return(false);
     }
     if (!XamlName.IsValidNameStartChar(name[0]))
     {
         return(false);
     }
     for (int i = 1; i < name.Length; i++)
     {
         if (!XamlName.IsValidQualifiedNameCharPlus(name[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Example #12
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);
            }
        }
Example #13
0
 private XamlType CreateErrorXamlType(XamlName name, string xmlns)
 {
     return(new XamlType(xmlns, name.Name, null, _parserContext.SchemaContext));
 }