当前位置: 首页>>代码示例>>C#>>正文


C# CsElement.AddElement方法代码示例

本文整理汇总了C#中CsElement.AddElement方法的典型用法代码示例。如果您正苦于以下问题:C# CsElement.AddElement方法的具体用法?C# CsElement.AddElement怎么用?C# CsElement.AddElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsElement的用法示例。


在下文中一共展示了CsElement.AddElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseElementContainerBody

        /// <summary>
        /// Parses the body of a container element.
        /// </summary>
        /// <param name="element">The element to parse.</param>
        /// <param name="elementReference">A reference to the element being created.</param>
        /// <param name="partialElements">The collection of partial elements found while parsing the files.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the closing curly bracket.</returns>
        private Node<CsToken> ParseElementContainerBody(
            CsElement element, Reference<ICodePart> elementReference, Dictionary<string, List<CsElement>> partialElements, bool unsafeCode)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(elementReference, "elementReference");
            Param.Ignore(partialElements);
            Param.Ignore(unsafeCode);

            Node<CsToken> closingBracketNode = null;

            // Keep looping until all the child elements within this container element have been processed.
            while (true)
            {
                // Saves the attributes and xml header for the element, if any exist.
                XmlHeader xmlHeader = null;
                ICollection<Attribute> attributes;

                var childElementReference = new Reference<ICodePart>();

                // Move past whitespace, preprocessors, comments, xml headers, and attributes, up to the
                // start of the element.
                this.MoveToElementDeclaration(elementReference, childElementReference, unsafeCode, out xmlHeader, out attributes);

                // Now record whether the element is within a generated code block.
                bool generated = this.symbols.Generated;

                // If the next symbol is a closing curly bracket, or we've reached the end of the symbols list,
                // we're done with this element.
                Symbol symbol = this.symbols.Peek(1);
                if (symbol == null)
                {
                    // We've reached the end of the document.
                    childElementReference.Target = element;
                    break;
                }
                else if (symbol.SymbolType == SymbolType.CloseCurlyBracket)
                {
                    // We've reached the end of the element. Save the closing bracket and exit.
                    Bracket bracket = this.GetBracketToken(CsTokenType.CloseCurlyBracket, SymbolType.CloseCurlyBracket, elementReference);
                    closingBracketNode = this.tokens.InsertLast(bracket);
                    childElementReference.Target = element;
                    break;
                }

                // Figure out the type of the next child element.
                ElementType? childElementType = this.GetElementType(element, unsafeCode);

                // If the type of the element could not be determined, then there must be
                // a syntax error in the code.
                if (childElementType == null ||
                    !SanityCheckElementTypeAgainstParent(childElementType.Value, element))
                {
                    throw this.CreateSyntaxException();
                }

                // Parse the element.
                CsElement childElement = this.ParseElement(
                    childElementType.Value, element, childElementReference, partialElements, unsafeCode, generated, xmlHeader, attributes);

                // Add any suppressed rules.
                this.AddRuleSuppressionsForElement(childElement);

                // Add the element to its parent.
                element.AddElement(childElement);

                // Set up the new element.
                this.InitializeElement(childElement);

                // Add the element to the collection of partial elements, if necessary.
                AddElementToPartialElementsList(childElement, partialElements);
            }

            return closingBracketNode;
        }
开发者ID:katerina-marchenkova,项目名称:my,代码行数:82,代码来源:CodeParser.Elements.cs

示例2: ParseElementContainerBody

 private Microsoft.StyleCop.Node<CsToken> ParseElementContainerBody(CsElement element, Dictionary<string, List<CsElement>> partialElements, bool unsafeCode)
 {
     Microsoft.StyleCop.Node<CsToken> node = null;
     while (true)
     {
         ICollection<Microsoft.StyleCop.CSharp.Attribute> is2;
         XmlHeader xmlHeader = null;
         this.MoveToElementDeclaration(unsafeCode, out xmlHeader, out is2);
         bool generated = this.symbols.Generated;
         Symbol symbol = this.symbols.Peek(1);
         if (symbol == null)
         {
             return node;
         }
         if (symbol.SymbolType == SymbolType.CloseCurlyBracket)
         {
             Bracket bracketToken = this.GetBracketToken(CsTokenType.CloseCurlyBracket, SymbolType.CloseCurlyBracket);
             return this.tokens.InsertLast(bracketToken);
         }
         ElementType? elementType = this.GetElementType(element, unsafeCode);
         if (!elementType.HasValue || !SanityCheckElementTypeAgainstParent(elementType.Value, element))
         {
             throw this.CreateSyntaxException();
         }
         CsElement element2 = this.ParseElement(elementType.Value, element, partialElements, unsafeCode, generated, xmlHeader, is2);
         this.AddRuleSuppressionsForElement(element2);
         element.AddElement(element2);
         this.InitializeElement(element2);
         AddElementToPartialElementsList(element2, partialElements);
     }
 }
开发者ID:katerina-marchenkova,项目名称:my,代码行数:31,代码来源:CodeParser.cs


注:本文中的CsElement.AddElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。