コード例 #1
0
        /// <summary>
        /// Creates an instance whose underlying syntax tree item is the specified object.
        /// </summary>
        /// <remarks>
        /// This method is the only way to create non-empty instances.
        /// </remarks>
        /// <param name="syntaxTreeItem">The syntax tree item to wrap.</param>
        /// <returns>A <see cref="SyntaxTreeElement"/> which wraps the specified <paramref name="syntaxTreeItem"/>
        /// syntax tree element. It is never <c>null</c>, but if <c>syntaxTreeItem</c> is either <c>null</c> or not a valid
        /// syntax node, token or trivia, the empty <c>SyntaxTreeElement</c> is returned.</returns>
        public static SyntaxTreeElement Create(object syntaxTreeItem)
        {
            SyntaxTreeElement element = new SyntaxTreeElement();

            if (syntaxTreeItem != null)
            {
                SyntaxNode node = syntaxTreeItem as SyntaxNode;
                if (node != null)
                {
                    element.Node                  = node;
                    element.SyntaxKind            = element.Node.Kind();
                    element.Text                  = element.Node.ToString();
                    element.SyntaxElementCategory = SyntaxElementCategory.Node;
                    element.Span                  = element.Node.Span;
                }
                else if (syntaxTreeItem.GetType() == typeof(SyntaxToken))
                {
                    object token = syntaxTreeItem;
                    element.Token                 = (SyntaxToken)token;
                    element.SyntaxKind            = element.Token.Kind();
                    element.Text                  = element.Token.ToString();
                    element.SyntaxElementCategory = SyntaxElementCategory.Token;
                    element.Span                  = element.Token.Span;
                }
                else if (syntaxTreeItem.GetType() == typeof(SyntaxTrivia))
                {
                    object trivia = syntaxTreeItem;
                    element.Trivia                = (SyntaxTrivia)trivia;
                    element.SyntaxKind            = element.Trivia.Kind();
                    element.Text                  = element.Trivia.ToString();
                    element.SyntaxElementCategory = SyntaxElementCategory.Trivia;
                    element.Span                  = element.Trivia.Span;
                }
            }

            return(element);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyntaxVisitingEventArgs"/> class.
 /// </summary>
 /// <param name="syntaxTreeElement">The syntax tree element instance. If null, the "empty" <c>SyntaxTreeElement</c> is
 /// used.</param>
 /// <param name="state">The visiting state, that is, the location where the event is raised.</param>
 public SyntaxVisitingEventArgs(SyntaxTreeElement syntaxTreeElement, SyntaxVisitingState state)
 {
     SyntaxTreeElement = syntaxTreeElement ?? SyntaxTreeElement.Empty;
     State             = state;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SyntaxVisitingEventArgs"/> class.
 /// </summary>
 /// <param name="syntaxItem">The syntax item; either a syntax node, token or trivia. The object is used to construct
 /// a <see cref="SyntaxTreeElement"/> having the underlying syntax item. If <c>syntaxItem</c> is not one of these types,
 /// the "empty" <c>SyntaxTreeElement</c> is created.</param>
 /// <param name="state">An value of the <see cref="SyntaxVisitingState"/> enumeration that describes the location
 /// where the event is raised.</param>
 public SyntaxVisitingEventArgs(object syntaxItem, SyntaxVisitingState state)
     : this(SyntaxTreeElement.Create(syntaxItem), state)
 {
 }