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


C# SyntaxTrivia.Kind方法代码示例

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


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

示例1: VisitTrivia

        public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
        {
            if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia)
            {
                if (trivia == _region)
                {
                    _nests = 0;
                     return SyntaxFactory.ElasticSpace;
                }
                else if (_nests >= 0)
                {
                    _nests++;
                }
            }
            else if (trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
            {
                if (_nests == 0)
                {
                    _nests = -1;
                    return SyntaxFactory.ElasticSpace;
                }
                else if (_nests >= 0)
                {
                    _nests--;
                }
            }

            return base.VisitTrivia(trivia);
        }
开发者ID:miya2000,项目名称:RemoveRegionCodeRefactoringSample,代码行数:29,代码来源:RemoveRegionCodeRefactoringSampleProvider.cs

示例2: VisitTrivia

 public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
 {
     if (trivia.Kind() == SyntaxKind.WhitespaceTrivia ||
         trivia.Kind() == SyntaxKind.EndOfLineTrivia)
         return SyntaxTrivia(SyntaxKind.WhitespaceTrivia, string.Empty);
     return base.VisitTrivia(trivia);
 }
开发者ID:pgenfer,项目名称:mixinSharp,代码行数:7,代码来源:RemoveWhitespaceWriter.cs

示例3: VisitTrivia

            public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
            {
                SyntaxTrivia updatedTrivia = base.VisitTrivia(trivia);
                if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia ||
                    trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
                {
                    // Remove the trivia entirely by returning default(SyntaxTrivia).
                    updatedTrivia = default(SyntaxTrivia);
                }

                return updatedTrivia;
            }
开发者ID:miya2000,项目名称:RemoveRegionCodeRefactoringSample,代码行数:12,代码来源:FAQ.cs

示例4: VisitTrivia

            public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
            {
                SyntaxTrivia updatedTrivia = base.VisitTrivia(trivia);
                if (trivia.Kind() == SyntaxKind.RegionDirectiveTrivia ||
                    trivia.Kind() == SyntaxKind.EndRegionDirectiveTrivia)
                {
                    // Remove the trivia entirely by returning SyntaxFactory.ElasticSpace.
                    updatedTrivia = SyntaxFactory.ElasticSpace;
                }

                return updatedTrivia;
            }
开发者ID:miya2000,项目名称:RemoveRegionCodeRefactoringSample,代码行数:12,代码来源:FAQ2.cs

示例5: VisitTrivia

            public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
            {
                if (trivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
                {
                    if (IsBeginningOrEndOfDocumentComment(trivia))
                    {
                        return base.VisitTrivia(trivia);
                    }
                    else
                    {
                        var triviaText = trivia.ToFullString();

                        var newTriviaText = triviaText.AdjustIndentForXmlDocExteriorTrivia(
                                                _forceIndentation,
                                                _indentation,
                                                _indentationDelta,
                                                _optionSet.GetOption(FormattingOptions.UseTabs, LanguageNames.CSharp),
                                                _optionSet.GetOption(FormattingOptions.TabSize, LanguageNames.CSharp));

                        if (triviaText == newTriviaText)
                        {
                            return base.VisitTrivia(trivia);
                        }

                        var parsedNewTrivia = SyntaxFactory.DocumentationCommentExterior(newTriviaText);

                        return parsedNewTrivia;
                    }
                }

                return base.VisitTrivia(trivia);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:32,代码来源:CSharpTriviaFormatter.DocumentationCommentExteriorCommentRewriter.cs

示例6: UnsupportedTriviaKind

        private static bool UnsupportedTriviaKind(SyntaxTrivia trivia)
        {
            switch (trivia.Kind())
            {
            case SyntaxKind.WhitespaceTrivia:
            case SyntaxKind.EndOfLineTrivia:
            case SyntaxKind.MultiLineCommentTrivia:
                return false;

            default:
                return true;
            }
        }
开发者ID:robinsedlaczek,项目名称:StyleCopAnalyzers,代码行数:13,代码来源:SA1018CodeFixProvider.cs

示例7: IsMultiLine

 public static bool IsMultiLine(SyntaxTrivia trivia)
 {
     switch (trivia.Kind())
     {
         case SyntaxKind.EndOfLineTrivia:
             return true;
         case SyntaxKind.WhitespaceTrivia:
         case SyntaxKind.SingleLineCommentTrivia:
             return false;
         // todo could possibly optimize for structured trivia
         default:
             return trivia.ToFullString().IndexOf('\n') >= 0;
     }
 }
开发者ID:madelson,项目名称:MedallionCodeFormatter,代码行数:14,代码来源:RoslynHelpers.cs

示例8: AcceptableSingleLineTrivia

        private static bool AcceptableSingleLineTrivia(SyntaxTrivia trivia)
        {
            switch (trivia.Kind())
            {
            case SyntaxKind.WhitespaceTrivia:
            case SyntaxKind.EndOfLineTrivia:
                return true;

            case SyntaxKind.MultiLineCommentTrivia:
                var lineSpan = trivia.GetLineSpan();
                return lineSpan.StartLinePosition.Line == lineSpan.EndLinePosition.Line;

            default:
                return false;
            }
        }
开发者ID:hickford,项目名称:StyleCopAnalyzers,代码行数:16,代码来源:SA1103CodeFixProvider.cs

示例9: HasEmptyComment

            private bool HasEmptyComment(SyntaxTrivia trivia)
            {
                if (trivia.Kind() != SyntaxKind.SingleLineCommentTrivia)
                {
                    return false;
                }

                var triviaText = trivia.ToFullString();

                // double comment is a sign for stylecop to ignore that comment
                if (triviaText.IndexOf("////", StringComparison.Ordinal) != -1)
                {
                    return false;
                }

                var index = triviaText.IndexOf("//", StringComparison.Ordinal);

                if (index == -1)
                {
                    return false;
                }

                while (triviaText.Length > index && triviaText[index] == '/')
                {
                    index++;
                }

                if (triviaText.Length <= index)
                {
                    // empty comment
                    return true;
                }

                while (triviaText.Length > index && char.IsWhiteSpace(triviaText[index]))
                {
                    index++;
                }

                if (triviaText.Length <= index)
                {
                    // comment contains only whitespace
                    return true;
                }

                return false;
            }
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:46,代码来源:SA1120_CommentMustNotBeEmpty.cs

示例10: AnalyzeWhitespacesInTrivia

            private static void AnalyzeWhitespacesInTrivia(SyntaxTrivia trivia, ref AnalysisResult result)
            {
                // trivia already has text. getting text should be noop
                Debug.Assert(trivia.Kind() == SyntaxKind.WhitespaceTrivia);
                Debug.Assert(trivia.Width() == trivia.FullWidth());

                int space = 0;
                int tab = 0;
                int unknownWhitespace = 0;

                var text = trivia.ToString();
                for (int i = 0; i < trivia.Width(); i++)
                {
                    if (text[i] == ' ')
                    {
                        space++;
                    }
                    else if (text[i] == '\t')
                    {
                        if (result.Space > 0)
                        {
                            result.HasTabAfterSpace = true;
                        }

                        tab++;
                    }
                    else
                    {
                        unknownWhitespace++;
                    }
                }

                // set result
                result.Space += space;
                result.Tab += tab;
                result.HasUnknownWhitespace |= unknownWhitespace > 0;
                result.TreatAsElastic |= trivia.IsElastic();
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:38,代码来源:TriviaDataFactory.Analyzer.cs

示例11: VisitTrivia

		public override void VisitTrivia(SyntaxTrivia trivia)
		{
			if (trivia.Kind() != SyntaxKind.MultiLineDocumentationCommentTrivia)
			{
				base.VisitTrivia(trivia);
				return;
			}

			var tokens = trivia.ToFullString()
				.RemoveLeadingAndTrailingMultiLineComments()
				.SplitOnNewLines(StringSplitOptions.None);
			var builder = new StringBuilder();

			foreach (var token in tokens)
			{
				var currentToken = token.RemoveLeadingSpacesAndAsterisk();
				var decodedToken = System.Net.WebUtility.HtmlDecode(currentToken);
				builder.AppendLine(decodedToken);
			}

			var text = builder.ToString();
			var line = _firstVisit
				? trivia.SyntaxTree.GetLineSpan(trivia.Span).StartLinePosition.Line
				: _lineNumberOverride.GetValueOrDefault(0);

			this.Blocks.Add(new TextBlock(text, line));
		}
开发者ID:niemyjski,项目名称:elasticsearch-net,代码行数:27,代码来源:CodeWithDocumentationWalker.cs

示例12: OnPreprocessor

            private bool OnPreprocessor(SyntaxTrivia trivia, int currentIndex)
            {
                if (!SyntaxFacts.IsPreprocessorDirective(trivia.Kind()))
                {
                    return false;
                }

                if (!this.UseIndentation)
                {
                    return true;
                }

                // preprocessor must be at from column 0
                if (_indentation != 0)
                {
                    return true;
                }

                ResetStateAfterNewLine(currentIndex);
                return false;
            }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:21,代码来源:TriviaDataFactory.CodeShapeAnalyzer.cs

示例13: OnSkippedTokensOrText

            private bool OnSkippedTokensOrText(SyntaxTrivia trivia)
            {
                if (trivia.Kind() != SyntaxKind.SkippedTokensTrivia &&
                    trivia.Kind() != SyntaxKind.PreprocessingMessageTrivia)
                {
                    return false;
                }

                return Contract.FailWithReturn<bool>("This can't happen");
            }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:TriviaDataFactory.CodeShapeAnalyzer.cs

示例14: IsComment

 private static bool IsComment(SyntaxTrivia trivia)
 {
     return TriviaKinds.Contains(trivia.Kind());
 }
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:4,代码来源:Metrics.cs

示例15: VisitTrivia

            public override void VisitTrivia(SyntaxTrivia trivia)
            {
                bool isDocComment = SyntaxFacts.IsDocumentationCommentTrivia(trivia.Kind());
                if (isDocComment ||
                    trivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
                    trivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
                {
                    Results.AppendLine();
                    Results.Append(trivia.ToFullString().Trim());
                    Results.Append(" (Parent Token: ");
                    Results.Append(trivia.Token.Kind());
                    Results.Append(")");
                    if (isDocComment)
                    {
                        // Trivia for xml documentation comments have additional 'structure'
                        // available under a child DocumentationCommentSyntax.
                        Assert.True(trivia.HasStructure);
                        var documentationComment =
                            (DocumentationCommentTriviaSyntax)trivia.GetStructure();
                        Assert.True(documentationComment.ParentTrivia == trivia);
                        Results.Append(" (Structured)");
                    }
                }

                base.VisitTrivia(trivia);
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:26,代码来源:FAQ.cs


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