コード例 #1
0
        // Token: 0x060020F7 RID: 8439 RVA: 0x000979E8 File Offset: 0x00095BE8
        private void ProcessMarkupExtensionNodes()
        {
            int i = 0;

            while (i < this._markupExtensionNodes.Count)
            {
                XamlNode     xamlNode  = this._markupExtensionNodes[i] as XamlNode;
                XamlNodeType tokenType = xamlNode.TokenType;
                switch (tokenType)
                {
                case XamlNodeType.ElementStart:
                    this._bamlRecordWriter.WriteElementStart((XamlElementStartNode)xamlNode);
                    break;

                case XamlNodeType.ElementEnd:
                    this._bamlRecordWriter.WriteElementEnd((XamlElementEndNode)xamlNode);
                    break;

                case XamlNodeType.Property:
                    this._bamlRecordWriter.WriteProperty((XamlPropertyNode)xamlNode);
                    break;

                case XamlNodeType.PropertyComplexStart:
                    this._bamlRecordWriter.WritePropertyComplexStart((XamlPropertyComplexStartNode)xamlNode);
                    break;

                case XamlNodeType.PropertyComplexEnd:
                    this._bamlRecordWriter.WritePropertyComplexEnd((XamlPropertyComplexEndNode)xamlNode);
                    break;

                case XamlNodeType.PropertyArrayStart:
                case XamlNodeType.PropertyArrayEnd:
                case XamlNodeType.PropertyIListStart:
                case XamlNodeType.PropertyIListEnd:
                case XamlNodeType.PropertyIDictionaryStart:
                case XamlNodeType.PropertyIDictionaryEnd:
                case XamlNodeType.LiteralContent:
                    goto IL_1A2;

                case XamlNodeType.PropertyWithExtension:
                    this._bamlRecordWriter.WritePropertyWithExtension((XamlPropertyWithExtensionNode)xamlNode);
                    break;

                case XamlNodeType.PropertyWithType:
                    this._bamlRecordWriter.WritePropertyWithType((XamlPropertyWithTypeNode)xamlNode);
                    break;

                case XamlNodeType.Text:
                    this._bamlRecordWriter.WriteText((XamlTextNode)xamlNode);
                    break;

                default:
                    switch (tokenType)
                    {
                    case XamlNodeType.EndAttributes:
                        this._bamlRecordWriter.WriteEndAttributes((XamlEndAttributesNode)xamlNode);
                        break;

                    case XamlNodeType.PIMapping:
                    case XamlNodeType.UnknownTagStart:
                    case XamlNodeType.UnknownTagEnd:
                    case XamlNodeType.UnknownAttribute:
                        goto IL_1A2;

                    case XamlNodeType.KeyElementStart:
                        this._bamlRecordWriter.WriteKeyElementStart((XamlKeyElementStartNode)xamlNode);
                        break;

                    case XamlNodeType.KeyElementEnd:
                        this._bamlRecordWriter.WriteKeyElementEnd((XamlKeyElementEndNode)xamlNode);
                        break;

                    case XamlNodeType.ConstructorParametersStart:
                        this._bamlRecordWriter.WriteConstructorParametersStart((XamlConstructorParametersStartNode)xamlNode);
                        break;

                    case XamlNodeType.ConstructorParametersEnd:
                        this._bamlRecordWriter.WriteConstructorParametersEnd((XamlConstructorParametersEndNode)xamlNode);
                        break;

                    default:
                        goto IL_1A2;
                    }
                    break;
                }
                i++;
                continue;
IL_1A2:
                throw new InvalidOperationException(SR.Get("BamlWriterUnknownMarkupExtension"));
            }
            this._markupExtensionNodes.Clear();
        }
コード例 #2
0
 // Token: 0x06002335 RID: 9013 RVA: 0x000ACD32 File Offset: 0x000AAF32
 internal virtual void ConvertXamlToObject(XamlReaderHelper tokenReader, ReadWriteStreamManager streamManager, ParserContext context, XamlNode xamlNode, BamlRecordReader reader)
 {
     throw new InvalidOperationException(SR.Get("InvalidDeSerialize"));
 }
コード例 #3
0
 // Token: 0x06002334 RID: 9012 RVA: 0x000ACD32 File Offset: 0x000AAF32
 internal virtual void ConvertXamlToBaml(XamlReaderHelper tokenReader, ParserContext context, XamlNode xamlNode, BamlRecordWriter bamlWriter)
 {
     throw new InvalidOperationException(SR.Get("InvalidDeSerialize"));
 }
コード例 #4
0
 /// <summary>
 /// Called whenever items should be added to the nodes collections.
 /// </summary>
 void AddNodeToCollection(XamlNode xamlNode)
 {
     AddNodeToCollection(xamlNode, false, false);
 }
コード例 #5
0
        void AddNodeToCollection(XamlNode xamlNode, bool insert, bool insertAtStart)
        {

            bool addNodeToBuffer = true; // set to false if need to do TextProcessing.
            bool textNodeAdded = false; // need to track if the textNode passed in is going to be in the baml or not

            // if there is a preCount we currently only allow
            // text within,
            bool preserveText = false;

            // Do any text Node handling for cached text of if this is
            // a textNode
            // !! should always be something on the stack since we push the Root.
            TextFlowStackData textFlowData = (TextFlowStackData)_textFlowStack.Peek();
            Debug.Assert(null != textFlowData, "No data for TextFlow");

            // do any processing for Text whitespace.
            switch (xamlNode.TokenType)
            {
                // possible that top-level text may not have been processed yet so
                // if get an EndDocument check the buffer

                case XamlNodeType.DocumentEnd:
                    {
                        // possible to have Text in the Buffer for the
                        // EndDocument if there is text at the root.
                        textNodeAdded = CollapseAndAddTextNode(textFlowData, true /* stripAllRightWhitespace */);
                        break;
                    }

                // process as begin tag
                // could be start of a new flow or inline.
                case XamlNodeType.ElementStart:
                    {
                        XamlElementStartNode elementNode = (XamlElementStartNode)xamlNode;
                        Type typeRightTag = elementNode.ElementType;
                        Debug.Assert(null != typeRightTag, "ElementType not yet assigned to Node");

                        // get whitespace type for tag
                        bool rightTagTrimSurroundingWhitespace = GetTrimSurroundingWhitespace(typeRightTag);
                        bool stripAllRightWhitespace = rightTagTrimSurroundingWhitespace;

                        // now have enough information on what to do with
                        // any textFlowData. If there isn't any
                        // text set the stripNextTextNodesLeadingWhitespace = to the current
                        // value.
                        // so inline the whitespace still gets stripped on the next
                        // tag <Button><B> This is Text </B> or should it be false?
                        // for block and inline block the stripNextTextNodesLeadingWhitespace
                        // will be updated based on if block or Inline.

                        textNodeAdded = CollapseAndAddTextNode(textFlowData, stripAllRightWhitespace);
                        textFlowData.StripLeadingSpaces = rightTagTrimSurroundingWhitespace;
                        TextFlowStackData flowData = new TextFlowStackData();
                        TextFlowStack.Push(flowData);

                        break;
                    }
                // process as text buffer
                case XamlNodeType.Text:
                {
                    // If we already have a text node, and we've encountered an ignorable element
                    // like a comment, then just append the new text to the existing text node
                    if (textFlowData.EncounteredIgnorableTag && textFlowData.TextNode != null)
                    {
                        textFlowData.TextNode.UpdateText(textFlowData.TextNode.Text +
                                                         ((XamlTextNode)xamlNode).Text);
                        textFlowData.EncounteredIgnorableTag = false;
                        addNodeToBuffer = false;
                    }
                    else
                    {
                        // !!! important set addNodeToBuffer to false so passed in text isn't added yet
                        // to the outputBuffer.
                        addNodeToBuffer = false;
                        textNodeAdded = CollapseAndAddTextNode(textFlowData, false /* stripAllRightWhitespace */);

                        // set the new text as the TextRun and update leading spaces
                        textFlowData.TextNode = (XamlTextNode)xamlNode;

                        // set the Prserve value check for if the xml:space = "preserve"
                        if (preserveText || (null != ParserContext.XmlSpace &&
                            ParserContext.XmlSpace.Equals("preserve")))
                        {
                            textFlowData.XmlSpaceIsPreserve = true;
                        }
                        else
                        {
                            textFlowData.XmlSpaceIsPreserve = false;
                        }
                    }
                }
                break;

                // process as end tag
                case XamlNodeType.ElementEnd:
                    {
                        // if this is not inline element then else it is
                        // okay to leave them.

                        // strip any trailing space unless this is an end to an inline tag.
                        bool stripAllRightWhitespace;
                        if (textFlowData.InlineCount > 0)
                        {
                            stripAllRightWhitespace = false;
                        }
                        else
                        {
                            stripAllRightWhitespace = true;
                        }

                        textNodeAdded = CollapseAndAddTextNode(textFlowData, stripAllRightWhitespace);

                        // if this is inline then decrement the inline count
                        // else pop the stack
                        if (textFlowData.InlineCount > 0)
                        {
                            textFlowData.InlineCount--;
                        }
                        else
                        {
                            TextFlowStack.Pop();
                        }
                    }
                    break;

                // treat as tags are not there but keep track for flows.
                // i.e. don't process text in buffer on either start tag.
                case XamlNodeType.PropertyComplexStart:
                case XamlNodeType.PropertyArrayStart:
                case XamlNodeType.PropertyIListStart:
                case XamlNodeType.PropertyIDictionaryStart:
                    {
                        // If we've accumulated whitespace text before the start of a
                        // property tag, then empty out that text, since property tags
                        // shouldn't cause whitespace text content to be realized.
                        if (textFlowData.TextNode != null)
                        {
                            if (IsWhitespace(textFlowData.TextNode.Text))
                            {
                                textFlowData.TextNode.UpdateText(string.Empty);
                            }
                            else
                            {
                                textNodeAdded = CollapseAndAddTextNode(textFlowData, /*stripAllRightWhitespace:*/true);
                            }
                        }
                        TextFlowStackData flowData = new TextFlowStackData();
                        TextFlowStack.Push(flowData);
                        break;
                    }

                // pop the stack shouldn't be any text to process.
                case XamlNodeType.PropertyComplexEnd:
                case XamlNodeType.PropertyArrayEnd:
                case XamlNodeType.PropertyIListEnd:
                case XamlNodeType.PropertyIDictionaryEnd:
                    Debug.Assert(0 == textFlowData.InlineCount, "Text stack still has an inline count");
                    textNodeAdded = CollapseAndAddTextNode(textFlowData, /*stripAllRightWhitespace:*/true);
                    _textFlowStack.Pop();
                    break;

                default:
                    break;
            }


            //If we aren't waiting to figure out when the textnode ends
            if (addNodeToBuffer)
            {
                //If a textnode was added to the baml (whitespace collapsing, etc... may cause textnodes to not be put into baml)
                //then we want to make sure that the parent of the textnode has the correct number of children.  The parent may either have
                //one or n children.  We also enforce that content can't be split up by property elements.
                if (textNodeAdded)
                {
                    bool isPropertyStartNode = false;

                    // ElementStart and Property*Start (which are XML Elements) each
                    // push a new context frame.  So for those, look in the parent.
                    ElementContextStackData textContext;
                    switch (xamlNode.TokenType)
                    {
                        case XamlNodeType.ElementStart:
                            textContext = ParentContext;
                            break;

                        case XamlNodeType.PropertyComplexStart:
                        case XamlNodeType.PropertyArrayStart:
                        case XamlNodeType.PropertyIListStart:
                        case XamlNodeType.PropertyIDictionaryStart:
                            textContext = ParentContext;
                            isPropertyStartNode = true;
                            break;
                        default:
                            textContext = CurrentContext;
                            break;
                    }

                    // Verify... "throw"s if we are "After" Content and
                    // returns false if there are multiple elements but
                    // the property is not a container.
                    if (!VerifyContentPropertySeesAnElement(textContext))
                    {
                        //only allow the 2nd (thru Nth) add if ContentPropertyInfo is a Collection (IList, etc...)
                        //Would be nicer to get real string here, but that would require more caching during the non-error cases.
                        throw new InvalidOperationException(SR.Get(SRID.ParserCanOnlyHaveOneChild,
                            textContext.ContextDataType.Name /* Parent */,
                            (textFlowData.TextNode == null ? "" : textFlowData.TextNode.Text) /* Child */));
                    }

                    if(isPropertyStartNode)
                        textContext.ContentParserState = ParsingContent.After;
                }

                if (insert)
                {
                    if (insertAtStart)
                    {
                        TokenReaderNodeCollection.InsertAtStartMark(xamlNode);
                    }
                    else
                    {
                        TokenReaderNodeCollection.InsertAtCurrentMark(xamlNode);
                    }
                }
                else
                {
                    TokenReaderNodeCollection.Add(xamlNode);
                }
            }
        }
コード例 #6
0
            // A new node has been added to the end of the XamlNode queue.
            //  See if this invalidates TypeConverter syntax.
            private void ExamineAddedNode(XamlNode xamlNode)
            {
                if( _typeConverterDecisionState == TypeConverterDecisionState.Uninitialized )
                {
                    // Starting a new element.
                    if( xamlNode.TokenType == XamlNodeType.ElementStart )
                    {
                        _typeConverterDecisionState = TypeConverterDecisionState.ElementStart;
                        _typeConverterCandidateIndex = _xamlNodes.Count - 1;

                        Debug.Assert(((XamlNode)_xamlNodes[_typeConverterCandidateIndex])==xamlNode,
                            "The node at the end of the queue is supposed to be the node we're examining.  Determine why the two don't match.");
                    }
                }
                else if( _typeConverterDecisionState == TypeConverterDecisionState.ElementStart )
                {
                    // Starting another new element.
                    if( xamlNode.TokenType == XamlNodeType.ElementStart )
                    {
                        // We've got an ElementStart inside another ElementStart
                        // The previous ElementStart could not be created via TypeConverter because
                        //  it needs to include this new Element.  But the new element might be a
                        //  candidate for TypeConverter creation.
                        // To handle this case, we stay in the ElementStart mode, but move the
                        //  candidate pointer to the new ElementStart.

                        // <Element>      <-- We started with this guy as TypeConverter candidate
                        //  <Element2>    <-- This is our current node, and the new candidate
                        //   TypeConverterText
                        //  </Element2>
                        // </Element>

                        _typeConverterCandidateIndex = _xamlNodes.Count - 1;

                        Debug.Assert(((XamlNode)_xamlNodes[_typeConverterCandidateIndex])==xamlNode,
                            "Supposedly we've just seen a new ElementStart, but it's not actually at the end of the XamlNode queue.  Determine why the two are out of [....].");
                    }
                    // This is the beginning of a large chunk of XamlNodes generated from
                    //  MarkupExtension information inside a x:Key value.  We ignore everything
                    //  inside this block and will return to the ElementStart state when this block ends.
                    // This logic needs to change if we start allowing nested KeyElements.
                    else if( xamlNode.TokenType == XamlNodeType.KeyElementStart )
                    {
                        _typeConverterDecisionState = TypeConverterDecisionState.IgnoringKeyElements;
                    }
                    // Text for new element's TypeConverter
                    else if( xamlNode.TokenType == XamlNodeType.Text )
                    {
                        _typeConverterDecisionState = TypeConverterDecisionState.InitializationString;

                        Debug.Assert( _typeConverterTextWrittenAndNotProcessed != null,
                            "The caller had sent out TypeConverter initialization text - we should be seeing it now.");
                    }
                    else if( NodeTypePrecludesTypeConverterUse(xamlNode) )
                    {
                        // Reset state since this node isn't permitted in TypeConverter usage.
                        ResetTypeConverterDecision();
                    }
                    else
                    {
                        // Everything else are tolerated for TypeConverter use.
                    }
                }
                else if( _typeConverterDecisionState == TypeConverterDecisionState.IgnoringKeyElements )
                {
                    // We saw KeyElementStart, keep going until we see KeyElementEnd.
                    // This logic needs to change if we start allowing nested KeyElements.
                    if( xamlNode.TokenType == XamlNodeType.KeyElementEnd )
                    {
                        // Now we can resume examining things on the Element start tag.
                        _typeConverterDecisionState = TypeConverterDecisionState.ElementStart;
                    }
                }
                else if( _typeConverterDecisionState == TypeConverterDecisionState.InitializationString )
                {
                    // We've just seen the InitializationString, we expect it to be immediately
                    //  followed by an ElementEnd.
                    if( xamlNode.TokenType == XamlNodeType.ElementEnd )
                    {
                        Debug.Assert(((XamlNode)_xamlNodes[_typeConverterCandidateIndex]).TokenType==XamlNodeType.ElementStart,
                            "We've lost track of the ElementStart node, and we're about to die with a cast exception.  See if the ElementStart is still in the ArrayList somewhere, and find out why the pointer got out of [....].");

                        // We've seen the full <ElementStart>InitializationText</ElementEnd> sequence.
                        ((XamlElementStartNode)_xamlNodes[_typeConverterCandidateIndex]).CreateUsingTypeConverter = true;

                        // The initializationString would be used as input to the candidate element's TypeConverter.
                        _typeConverterTextWrittenAndNotProcessed = null;
                    }
                    else
                    {
                        // Example that would trip this error:
                        //  <FontFamily>Symbol<Button/></FontFamily>
                        throw new InvalidOperationException(SR.Get(SRID.ParserTypeConverterTextNeedsEndElement, _typeConverterTextWrittenAndNotProcessed));
                    }

                    // One set of XamlNodes for TypeConverter done, start watching for another.
                    ResetTypeConverterDecision();
                }
                return;
            }
コード例 #7
0
            // Checking the given XamlNode against the list of types that we know will
            //  break our ability to use TypeConverter.
            private bool NodeTypePrecludesTypeConverterUse(XamlNode xamlNode)
            {
                XamlNodeType tokenType = xamlNode.TokenType;

                switch(tokenType)
                {
                    /////////////////////////////////////////////////////////////
                    //
                    // These XamlNode types will prevent us from using the TypeConverter syntax.

                    // Simple property setting is not allowed.
                    //  No: <SolidColorBrush Opacity="0.5">Red</SolidColorBrush>
                    case XamlNodeType.Property:
                        BamlAttributeUsage attributeUsage = ((XamlPropertyNode)xamlNode).AttributeUsage;

                        if( attributeUsage == BamlAttributeUsage.XmlSpace )
                        {
                            // An exception: xml:space is tolerated.  ParserContext
                            //  is set, and text processing is handled accordingly, but
                            //  the XmlAttributeProperties.XmlSpaceProperty attached DP
                            //  will not be set on this element.

                            // Example:
                            //  <SolidColorBrush xml:space="preserve">   Red   </SolidColorBrush>
                            //  BrushConverter will get "   Red   " instead of the collapsed "Red",
                            //  but the SolidColorBrush will not get the XmlSpaceProperty attached DP.

                            return false;
                        }
                        return true;

                    // None of the PropertyWithType nodes are allowed in conjuction with a TypeConverter
                    case XamlNodeType.PropertyWithType:

                    // This node represents a simple MarkupExtension value and should not be allowed in
                    // conjuntion with a TypeConverter
                    case XamlNodeType.PropertyWithExtension:

                    // No complex property (or variant) is allowed in TypeConverter syntax
                    case XamlNodeType.PropertyComplexStart:
                    case XamlNodeType.PropertyComplexEnd:
                    case XamlNodeType.PropertyArrayStart:
                    case XamlNodeType.PropertyArrayEnd:
                    case XamlNodeType.PropertyIListStart:
                    case XamlNodeType.PropertyIListEnd:
                    case XamlNodeType.PropertyIDictionaryStart:
                    case XamlNodeType.PropertyIDictionaryEnd:

                    // Events may not be set on a TypeConverter-created object
                    case XamlNodeType.RoutedEvent:
                    case XamlNodeType.ClrEvent:

                    // These are involved in an entirely different kind of delay creation.
                    case XamlNodeType.ConstructorParametersStart:
                    case XamlNodeType.ConstructorParametersEnd:
                    case XamlNodeType.ConstructorParameterType:

                    // Content use is mutually exclusive with TypeConverter use -
                    //  By this point we've decided Text will be Content, not TypeConverter input.
                    case XamlNodeType.ContentProperty:

                    // We don't know what these are, so we can't guarantee that
                    //  TypeConvert will work.
                    case XamlNodeType.Unknown:
                    case XamlNodeType.UnknownTagStart:
                    case XamlNodeType.UnknownTagEnd:
                    case XamlNodeType.UnknownAttribute:

                    // Definition tags are non-text content and breaks the
                    //  text content only rule for TypeConverter information.
                    case XamlNodeType.DefTag:

                    // This means a tag like <Linebreak /> where End immediately follows Start.
                    //  There's nothing for a TypeConverter to do here.
                    case XamlNodeType.ElementEnd:

                        return true;

                    /////////////////////////////////////////////////////////////
                    //
                    // These tags are tolerated while looking for TypeConverter info

                    // This is expected when we hit the end of the start tag.
                    case XamlNodeType.EndAttributes:

                    // XML namespace definitions are OK
                    case XamlNodeType.XmlnsProperty:

                    // When XMLNS is used to define reference to assembly, that causes
                    //  a PIMapping node to be generated under the covers.  "PIMapping" used
                    //  to be their own tags in the markup, but were removed from the
                    //  XAML syntax.  Rather than changing the parser to actually match the
                    //  new XAML syntax, this magic-mapping is done instead so we pretend
                    //  to use the new XAML syntax while we're still really doing the old
                    //  things under the covers.
                    case XamlNodeType.PIMapping:

                    // This property affects what we do with an object after we've
                    //  created the instance.  It does not affect whether we use
                    //  a TypeConverter to create it.
                    case XamlNodeType.PresentationOptionsAttribute:
                        return false;

                    /////////////////////////////////////////////////////////////
                    //
                    // XAML Directive Attributes - a whole funhouse of special cases.

                    case XamlNodeType.DefAttribute:
                        string nodeName = ((XamlDefAttributeNode)xamlNode).Name;

                        if( nodeName == DefinitionRuntimeName )
                        {
                            // In an ideal world, x:Name would be tolerated.
                            // Unfortunately, due to a collision with how
                            //  RuntimeIdentifierPropertyAttribute is implemented,
                            //  x:Name breaks our ability to use TypeConverter.
                            return true;
                        }
                        else if( nodeName == DefinitionTypeArgs )
                        {
                            // x:TypeArguments tells the parser the Type to use
                            //  when creating an instance of a generic.  (IList<T>, etc.)
                            // We do not have any way of passing this type information
                            //  into TypeConverter creation, so this is not
                            //  supported in the TypeConverter syntax.
                            return true;
                        }
                        else if( nodeName == DefinitionFieldModifier ||
                                 nodeName == DefinitionClassModifier )
                        {
                            // These attributes are used to modify the code access
                            //  level of generated classes.  (Internal/Public,etc.)
                            // We cannot use a TypeConverter to create an instance
                            //  of a class defined in a generated file.
                            return true;
                        }
                        return false;

                    // This is a x:Key="{x:Type ----}" when the ---- type
                    //  could not be resolved at parse/compile time.  (Or else it
                    //  would be KeyElementStart(TypeExtension)/KeyElementEnd.)
                    // This does not prevent us from using TypeConverter.
                    case XamlNodeType.DefKeyTypeAttribute:
                        return false;

                    /////////////////////////////////////////////////////////////
                    //
                    // Nodes we don't expect to see.

                    // These node types were supposed to be handled by the caller.
                    case XamlNodeType.ElementStart:
                    case XamlNodeType.Text:
                    case XamlNodeType.KeyElementStart:
                    case XamlNodeType.KeyElementEnd:

                    // These are not handled by immediate caller, but we expect
                    //  them to have been handled further upstream.
                    case XamlNodeType.DocumentStart:
                    case XamlNodeType.DocumentEnd:
                    case XamlNodeType.Comment:
                    case XamlNodeType.LiteralContent:
                    case XamlNodeType.ProcessingInstruction:

                    // If not any of the above node types, then we have a new
                    //  XamlNode type that must be evaluated for TypeConverter
                    //  compatibility.

                    default:
                        Debug.Assert(false,"State machine checking for TypeConverter syntax has encountered an unexpected XamlNode type " + tokenType);

                        // If we didn't expect it - assume it invalidates our ability
                        //  to use a TypeConverter.
                        return true;
                }

            }
コード例 #8
0
 // A new node has been inserted into the middle of the XamlNode queue.
 //  See if this invalidates TypeConverter syntax.
 private void ExamineInsertedNode(XamlNode xamlNode, int insertionIndex)
 {
     if( _typeConverterDecisionState != TypeConverterDecisionState.Uninitialized )
     {
         // This method only cares about the new node if we're in the middle of
         //  a potential TypeConverter sequence.
         // This is a shortcut enabled by the current design, where only a
         //  limited set of XamlNodes can be legally inserted out-of-order.
         if( NodeTypePrecludesTypeConverterUse(xamlNode) )
         {
             // The newly inserted node breaks our ability to use TypeConverter
             ResetTypeConverterDecision();
         }
         else if( _typeConverterCandidateIndex >= insertionIndex )
         {
             // Update the pointer to the candidate ElementStart.
             _typeConverterCandidateIndex++;
             Debug.Assert(((XamlNode)_xamlNodes[_typeConverterCandidateIndex]).TokenType==XamlNodeType.ElementStart,
                 "We've lost track of the ElementStart XamlNode after an XamlNode insertion.");
         }
     }
     return;
 }
コード例 #9
0
            // Inserts node at current index that is updated with each insertion.
            // This is currently used only for event attribute nodes.
            internal void InsertAtCurrentMark(XamlNode xamlNode)
            {
#if DBG
                Debug.Assert(IsMarkedForInsertion, "Attribute node collection is not marked for insertion.");
#endif
                _xamlNodes.Insert(_currentInsertionIndex, xamlNode);
                ExamineInsertedNode(xamlNode, _currentInsertionIndex );

                _currentInsertionIndex++;
            }
コード例 #10
0
            //////////////////////////////////////////////////////////////////////////
            //
            //  First-In First-Out queue operations

            /// <summary>
            /// Enqueues the given node to the end of the ArrayList buffer.
            /// </summary>
            internal void Add(XamlNode xamlNode)
            {
                _xamlNodes.Add(xamlNode);

                ExamineAddedNode(xamlNode);
            }
コード例 #11
0
        /// <summary>
        /// Reads the next XamlNode
        /// </summary>
        /// <param name="xamlNode">pointer to the XamlNode Read</param>
        /// <returns>true if a Nodes was read, False if no more nodes.</returns>
        internal bool Read(ref XamlNode xamlNode)
        {
            xamlNode = null;

            // see if there is a node in the buffer and if so just return it
            if (TokenReaderNodeCollection.Count > 0)
            {
                xamlNode = TokenReaderNodeCollection.Remove();
                Debug.Assert(null != xamlNode, "null returned from the collection");
                return true;
            }

            if (CurrentContext != null && CurrentContext.IsEmptyElement)
            {
                // if the current element on the stack is an empty element,
                // we need pop the stack here as all its attributes would
                // have already been processed by the XamlParser.
                ElementContextStack.Pop();
                ParserContext.PopScope();
            }

            // the the parseLoop is done, just return false
            if (ParseLoopState == ParserState.Done)
            {
                xamlNode = null;
                return false;
            }

#if PBTCOMPILER || !STRESS
            try // What do we do with Exceptions we catch on this thread?.
            {
#endif

                // Do any processing specific to the
                // first time Read is called
                if (ParseLoopState == ParserState.Uninitialized)
                {
                    Debug.Assert(null != XmlReader);
                    ParseLoopState = ParserState.Reading;

                    WriteDocumentStart(); // write the document node.

                    XmlReader.Read(); // first time thru get to the first start tag.
                }

                // loop calling the appropriate context handler
                // !! when calling we pass in a NodeType which should be used
                // to determine the nodeState. This is necessary for the case of an
                // empty tag.
                // keep reading while there is no data and we don't have
                // any items in the Node collection to return.
                while (ContinueReading)
                {

                    // read based on the node type.
                    switch (XmlReader.NodeType)
                    {
                        case XmlNodeType.Element:
                            ReadElementNode();
                            break;
                        case XmlNodeType.EndElement:
                            ReadEndElementNode(false);
                            break;
                        default:
                            ReadGenericXmlNode();
                            break;
                    }

                }

                // If there aren't any nodes in the buffer when come out of
                // loop means we are done with the XML, so set the state
                // to done and write the EndDocument.

                if (0 >= TokenReaderNodeCollection.Count && ParseLoopState != ParserState.Done)
                {
                    Debug.Assert(!IsMoreData(), "Setting state to done but not done parsing.");
                    ParseLoopState = ParserState.Done;
                    WriteDocumentEnd();
                }
#if PBTCOMPILER || !STRESS
            }
            catch (XamlParseException e)
            {
                throw e;
            }
            catch (XmlException e)
            {
                // if it is an XML Exception use the lineNumber/position they tell us.
                RethrowAsParseException(e.Message, e.LineNumber, e.LinePosition, e);
            }
            catch (Exception e)
            {
                if (CriticalExceptions.IsCriticalException(e))
                {
                    throw;
                }
                else
                {
                    // generic exception, use current linenumber, position form XmlReader.
                    RethrowAsParseException(e.Message, LineNumber, LinePosition, e);
                }
            }
#endif

            // see if there is a node in the buffer and if so return it.
            if (TokenReaderNodeCollection.Count > 0)
            {
                xamlNode = TokenReaderNodeCollection.Remove();
                Debug.Assert(null != xamlNode, "null returned from the collection");
                return true;
            }

            return false;
        }
コード例 #12
0
 // Token: 0x06002202 RID: 8706 RVA: 0x0000B02A File Offset: 0x0000922A
 internal virtual ParserAction LoadNode(XamlNode tokenNode)
 {
     return(ParserAction.Normal);
 }