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


C# SyntaxTrivia.IsKind方法代码示例

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


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

示例1: IsComment

 private static bool IsComment(SyntaxTrivia trivia)
 {
     return trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) ||
         trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) ||
         trivia.IsKind(SyntaxKind.SingleLineDocumentationCommentTrivia) ||
         trivia.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia);
 }
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:7,代码来源:CommentWordBase.cs

示例2: VisitTrivia

            public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
            {
                var retVal = default(SyntaxTrivia);
                var isRegionOrEndRegionStructuredTrivia = trivia.HasStructure &&
                    (trivia.IsKind(SyntaxKind.RegionDirectiveTrivia) ||
                     trivia.IsKind(SyntaxKind.EndRegionDirectiveTrivia));

                if (isRegionOrEndRegionStructuredTrivia)
                {
                    this.addedAnnotations = true;
                    // Simply return default(SyntaxTrivia)
                }
                else
                {
                    retVal = base.VisitTrivia(trivia);
                }

                return retVal;
            }
开发者ID:OliverKurowski,项目名称:StylecopCodeFormatter,代码行数:19,代码来源:SA1124_NoRegionsAllowed.cs

示例3: IsTriviaComment

 protected override bool IsTriviaComment(SyntaxTrivia trivia) =>
     trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineCommentTrivia);
开发者ID:Thejas007,项目名称:sonarlint-vs,代码行数:2,代码来源:GeneratedCodeRecognizer.cs

示例4: TryGetDirective

 static bool TryGetDirective(SyntaxNode root, TextSpan span, out SyntaxTrivia directive)
 {
     directive = root.FindTrivia(span.Start);
     return directive.IsKind(SyntaxKind.RegionDirectiveTrivia) || directive.IsKind(SyntaxKind.EndRegionDirectiveTrivia);
 }
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:5,代码来源:RemoveRegionEndRegionDirectivesCodeRefactoringProvider.cs

示例5: GetTriviaContent

        private static string GetTriviaContent(SyntaxTrivia trivia)
        {
            var triviaContent = trivia.ToString();
            if (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia))
            {
                if (triviaContent.StartsWith("/*", StringComparison.InvariantCulture))
                {
                    triviaContent = triviaContent.Substring(2);
                }

                if (triviaContent.EndsWith("*/", StringComparison.InvariantCulture))
                {
                    triviaContent = triviaContent.Substring(0, triviaContent.Length-2);
                }
                return triviaContent;
            }

            if (trivia.IsKind(SyntaxKind.SingleLineCommentTrivia))
            {
                if (triviaContent.StartsWith("//", StringComparison.InvariantCulture))
                {
                    triviaContent = triviaContent.Substring(2);
                }

                return triviaContent;
            }

            return string.Empty;
        }
开发者ID:Azzhag,项目名称:sonarlint-vs,代码行数:29,代码来源:CommentedOutCode.cs

示例6: IsTriviaComment

 protected override bool IsTriviaComment(SyntaxTrivia trivia) =>
     trivia.IsKind(SyntaxKind.CommentTrivia);
开发者ID:dbolkensteyn,项目名称:sonarlint-vs,代码行数:2,代码来源:GeneratedCodeRecognizer.cs

示例7: IsAllowedTrivia

 private static bool IsAllowedTrivia(SyntaxTrivia trivia)
 {
     return trivia.IsKind(SyntaxKind.WhitespaceTrivia)
         || trivia.IsKind(SyntaxKind.EndOfLineTrivia)
         || (trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) && !trivia.SpansMultipleLines());
 }
开发者ID:neugenes,项目名称:StyleCopAnalyzers,代码行数:6,代码来源:SA1504CodeFixProvider.cs

示例8: IsComment

 private static bool IsComment(SyntaxTrivia syntaxTrivia)
 {
     var isSingleLineComment = syntaxTrivia.IsKind(SyntaxKind.SingleLineCommentTrivia)
         && !syntaxTrivia.ToFullString().StartsWith(@"////", StringComparison.Ordinal);
     return isSingleLineComment
         || syntaxTrivia.IsKind(SyntaxKind.MultiLineCommentTrivia);
 }
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1108BlockStatementsMustNotContainEmbeddedComments.cs

示例9: SearchUsingInsertionPoint

		static int SearchUsingInsertionPoint (SyntaxNode parent)
		{
			var result = 0;
			foreach (SyntaxNode node in parent.ChildNodes ()) {
				if (node.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.UsingDirective)) {
					result = node.FullSpan.End;
					continue;
				}
				SyntaxTrivia last = new SyntaxTrivia ();

				foreach (var trivia in node.GetLeadingTrivia ()) {
					if (last.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.SingleLineCommentTrivia)||
						last.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.DefineDirectiveTrivia) || 
						last.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.MultiLineCommentTrivia) || 
						last.IsKind (Microsoft.CodeAnalysis.CSharp.SyntaxKind.SingleLineDocumentationCommentTrivia))
						result = trivia.Span.End;
					last = trivia;
				}
				break;
			}
			return result;
		}
开发者ID:gAdrev,项目名称:monodevelop,代码行数:22,代码来源:ImportSymbolCompletionData.cs

示例10: GetLineColumnRuleBetween

        protected override LineColumnRule GetLineColumnRuleBetween(SyntaxTrivia trivia1, LineColumnDelta existingWhitespaceBetween, bool implicitLineBreak, SyntaxTrivia trivia2)
        {
            if (IsStartOrEndOfFile(trivia1, trivia2))
            {
                return LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines: 0, indentation: 0);
            }

            // [trivia] [whitespace] [token] case
            if (trivia2.IsKind(SyntaxKind.None))
            {
                var insertNewLine = this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null;

                if (IsMultilineComment(trivia1))
                {
                    return LineColumnRule.PreserveLinesWithGivenIndentation(lines: insertNewLine ? 1 : 0);
                }

                if (insertNewLine)
                {
                    return LineColumnRule.PreserveLinesWithDefaultIndentation(lines: 0);
                }

                if (existingWhitespaceBetween.Lines > 0 && existingWhitespaceBetween.Spaces != this.Spaces)
                {
                    return LineColumnRule.PreserveWithGivenSpaces(spaces: this.Spaces);
                }

                return LineColumnRule.Preserve();
            }

            // preprocessor case
            if (SyntaxFacts.IsPreprocessorDirective(trivia2.Kind()))
            {
                // Check for immovable preprocessor directives, which are bad directive trivia 
                // without a preceding line break
                if (trivia2.IsKind(SyntaxKind.BadDirectiveTrivia) && existingWhitespaceBetween.Lines == 0 && !implicitLineBreak)
                {
                    _succeeded = false;
                    return LineColumnRule.Preserve();
                }

                // if current line is the first line of the file, don't put extra line 1
                var lines = (trivia1.IsKind(SyntaxKind.None) && this.Token1.IsKind(SyntaxKind.None)) ? 0 : 1;

                if (trivia2.IsKind(SyntaxKind.RegionDirectiveTrivia) || trivia2.IsKind(SyntaxKind.EndRegionDirectiveTrivia))
                {
                    return LineColumnRule.PreserveLinesWithDefaultIndentation(lines);
                }

                return LineColumnRule.PreserveLinesWithAbsoluteIndentation(lines, indentation: 0);
            }

            // comments case
            if (trivia2.IsRegularOrDocComment())
            {
                // start of new comments group
                if (!trivia1.IsRegularComment() || existingWhitespaceBetween.Lines > 1)
                {
                    if (this.FormattingRules.GetAdjustNewLinesOperation(this.Token1, this.Token2) != null)
                    {
                        return LineColumnRule.PreserveLinesWithDefaultIndentation(lines: 0);
                    }

                    return LineColumnRule.PreserveLinesWithGivenIndentation(lines: 0);
                }

                // comments after existing comment
                if (existingWhitespaceBetween.Lines == 0)
                {
                    return LineColumnRule.PreserveLinesWithGivenIndentation(lines: 0);
                }

                return LineColumnRule.PreserveLinesWithFollowingPrecedingIndentation();
            }

            if (trivia2.IsKind(SyntaxKind.SkippedTokensTrivia))
            {
                // if there is any skipped tokens, it is not possible to format this trivia range.
                _succeeded = false;
            }

            return LineColumnRule.Preserve();
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:83,代码来源:CSharpTriviaFormatter.cs

示例11: VisitTrivia

			public override void VisitTrivia (SyntaxTrivia trivia)
			{
				base.VisitTrivia (trivia);
				if (trivia.IsKind (SyntaxKind.RegionDirectiveTrivia)) {
					regionStack.Push (trivia);
				} else if (trivia.IsKind (SyntaxKind.EndRegionDirectiveTrivia)) {
					if (regionStack.Count == 0)
						return;
					var regionStart = regionStack.Pop ();
					try {
						var first = regionStart.GetLocation ().GetLineSpan ();
						var last = trivia.GetLocation ().GetLineSpan ();
						var v = regionStart.ToString ();
						v = v.Substring ("#region".Length).Trim ();
						if (v.Length == 0)
							v = "...";
						Foldings.Add (new FoldingRegion(v, new DocumentRegion(first.StartLinePosition, last.EndLinePosition), FoldType.UserRegion, true));
					} catch (ArgumentOutOfRangeException) { }
				}
			}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:20,代码来源:CSharpParsedDocument.cs

示例12: IsCodeComment

 private bool IsCodeComment(SyntaxTrivia trivia)
 {
     return trivia.IsKind(SyntaxKind.SingleLineCommentTrivia) ||
         trivia.IsKind(SyntaxKind.MultiLineCommentTrivia);
 }
开发者ID:bkoelman,项目名称:ResharperCodeContractNullability,代码行数:5,代码来源:GeneratedCodeDocumentCache.cs

示例13: OnDisabledTextTrivia

            private bool OnDisabledTextTrivia(SyntaxTrivia trivia, int index)
            {
                if (trivia.IsKind(SyntaxKind.DisabledTextTrivia))
                {
                    var triviaString = trivia.ToString();
                    if (!string.IsNullOrEmpty(triviaString) && SyntaxFacts.IsNewLine(triviaString.Last()))
                    {
                        ResetStateAfterNewLine(index);
                    }
                }

                return false;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:TriviaDataFactory.CodeShapeAnalyzer.cs

示例14: IsComment

 private bool IsComment(SyntaxTrivia syntaxTrivia)
 {
     var isSingleLineComment = syntaxTrivia.IsKind(SyntaxKind.SingleLineCommentTrivia)
         && !syntaxTrivia.ToFullString().StartsWith(@"////");
     return isSingleLineComment
         || syntaxTrivia.IsKind(SyntaxKind.MultiLineCommentTrivia);
 }
开发者ID:nvincent,项目名称:StyleCopAnalyzers,代码行数:7,代码来源:SA1108BlockStatementsMustNotContainEmbeddedComments.cs


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