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


C# SyntaxTrivia类代码示例

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


SyntaxTrivia类属于命名空间,在下文中一共展示了SyntaxTrivia类的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: IsBeginningOrEndOfDocumentComment

            private bool IsBeginningOrEndOfDocumentComment(SyntaxTrivia trivia)
            {
                var currentParent = trivia.Token.Parent;

                while (currentParent != null)
                {
                    if (currentParent.Kind() == SyntaxKind.SingleLineDocumentationCommentTrivia ||
                        currentParent.Kind() == SyntaxKind.MultiLineDocumentationCommentTrivia)
                    {
                        if (trivia.Span.End == currentParent.SpanStart ||
                            trivia.Span.End == currentParent.Span.End)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }

                    currentParent = currentParent.Parent;
                }

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

示例3: AddClassification

 private void AddClassification(SyntaxTrivia trivia, string type)
 {
     if (trivia.Width() > 0 && _textSpan.OverlapsWith(trivia.Span))
     {
         AddClassification(trivia.Span, type);
     }
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:7,代码来源:Worker.cs

示例4: GetRegions

 private IEnumerable<OutliningSpan> GetRegions(SyntaxTree syntaxTree, SyntaxTrivia trivia)
 {
     var outliner = new DisabledTextTriviaOutliner();
     var spans = new List<OutliningSpan>();
     outliner.CollectOutliningSpans(syntaxTree, trivia, spans, CancellationToken.None);
     return spans;
 }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:7,代码来源:DisabledTextOutlinerTests.cs

示例5: ReplaceTabWithFourSpacesAsync

 private Task<Document> ReplaceTabWithFourSpacesAsync(Document document, SyntaxNode root, SyntaxTrivia tabTrivia
     , CancellationToken cancellationToken)
 {
     SyntaxTrivia fourSpacesTrivia = SyntaxFactory.Whitespace(new string(' ', 4 * tabTrivia.Span.Length));
     SyntaxNode newRoot = root.ReplaceTrivia(tabTrivia, fourSpacesTrivia);
     return Task.FromResult(document.WithSyntaxRoot(newRoot));
 }
开发者ID:RickyLin,项目名称:CodingConventionsCop,代码行数:7,代码来源:IndentWithFourSpacesCodeFixProvider.cs

示例6: 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

示例7: NeedsSpaceAdding

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

            var text = trivia.ToFullString();

            if (!text.StartsWith("//"))
            {
                return false;
            }

            if (text.StartsWith("///") || text.StartsWith("////"))
            {
                return false;
            }

            if (text.Length >= 3 && text[2] != ' ')
            {
                return true;
            }

            if (text.Length >= 4 && text[2] == ' ' && text[3] == ' ')
            {
                return true;
            }

            return false;
        }
开发者ID:grokys,项目名称:StyleCopMagic,代码行数:31,代码来源:SA1005.cs

示例8: HandleSingleLineComment

        private static void HandleSingleLineComment(SyntaxTreeAnalysisContext context, SyntaxTrivia singleLineComment)
        {
            int index = 0;

            // PERF: Explicitly cast to IReadOnlyList so we only box once.
            IReadOnlyList<SyntaxTrivia> list = TriviaHelper.GetContainingTriviaList(singleLineComment, out index);
            var firstNonWhiteSpace = TriviaHelper.IndexOfFirstNonWhitespaceTrivia(list);

            // When we encounter a block of single line comments, we only want to raise this diagnostic
            // on the first or last line.  This ensures that whitespace in code commented out using
            // the Comment Selection option in Visual Studio will not raise the diagnostic for every
            // blank line in the code which is commented out.
            bool isFirst = index == firstNonWhiteSpace;
            if (!isFirst)
            {
                // This is -2 because we need to go back past the end of line trivia as well.
                var lastNonWhiteSpace = TriviaHelper.IndexOfTrailingWhitespace(list) - 2;
                if (index != lastNonWhiteSpace)
                {
                    return;
                }
            }

            if (IsNullOrWhiteSpace(singleLineComment.ToString(), 2))
            {
                var diagnostic = Diagnostic.Create(Descriptor, singleLineComment.GetLocation());
                context.ReportDiagnostic(diagnostic);
            }
        }
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:29,代码来源:SA1120CommentsMustContainText.cs

示例9: Evaluate

		public EvaluationResult Evaluate(SyntaxTrivia node)
		{
			var result = EvaluateImpl(node);
			if (result != null)
			{
				var sourceTree = node.GetLocation().SourceTree;
				var filePath = sourceTree.FilePath;
				var typeDefinition = GetNodeType(node.Token.Parent);
				var unitNamespace = GetNamespace(node.Token.Parent);
				if (result.ErrorCount == 0)
				{
					result.ErrorCount = 1;
				}

				result.LinesOfCodeAffected = 0;
				result.Namespace = unitNamespace;
				result.TypeKind = typeDefinition.Item1;
				result.TypeName = typeDefinition.Item2;
				result.Title = Title;
				result.Suggestion = Suggestion;
				result.Quality = Quality;
				result.QualityAttribute = QualityAttribute;
				result.ImpactLevel = ImpactLevel;
				result.FilePath = filePath;
			}

			return result;
		}
开发者ID:henrylle,项目名称:ArchiMetrics,代码行数:28,代码来源:TriviaEvaluationBase.cs

示例10: VisitTrivia

 public override void VisitTrivia(SyntaxTrivia trivia)
 {
     if (trivia.Kind != SyntaxKind.DocumentationCommentExteriorTrivia)
     {
         arg.Append(trivia.ToString());
     }
 }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:DocumentationCommentTriviaSyntax.cs

示例11: VisitTrivia

 public override void VisitTrivia(SyntaxTrivia trivia)
 {
     if (TriviaPredicate != null && TriviaAction != null && TriviaPredicate(trivia))
     {
         TriviaAction(trivia);
     }
 }
开发者ID:skrymsli,项目名称:Swasey,代码行数:7,代码来源:SyntaxTriviaWalker.cs

示例12: VisitTrivia

 public virtual void VisitTrivia(SyntaxTrivia trivia)
 {
     if (this.Depth >= SyntaxWalkerDepth.StructuredTrivia && trivia.HasStructure)
     {
         this.Visit((CSharpSyntaxNode)trivia.GetStructure());
     }
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:CSharpSyntaxWalker.cs

示例13: VisitTrivia

		public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
		{
			var comment = trivia.ToString();
			if (trivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
			{
				if (!comment.StartsWith("/*uncomment"))
				{
					bool shouldCreateTextBlock = trivia.GetParents().Count(p => IsNestingParent(p, trivia)) <= 1;
					if (shouldCreateTextBlock)
						Blocks.Add(ExtractMarkDownFromComment(trivia));
				}
			}
			else if (trivia.Kind() == SyntaxKind.SingleLineCommentTrivia)
			{
				if (comment.StartsWith("//#"))
				{
					var parts = comment.Split(new[] { ' ' }, 2);
					if (parts[0] == "//#video") EmbedVideo(parts[1]);
                    if (parts[0] == "//#include") EmbedCode(parts[1]);
                    if (parts[0] == "//#para") EmbedPara(parts[1]);
                    if (parts[0] == "//#gallery") EmbedGallery(parts[1]);
				}
			}
			return base.VisitTrivia(trivia);
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:25,代码来源:BlocksBuilder.cs

示例14: 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

示例15: AppendTodoComments

        protected override void AppendTodoComments(ImmutableArray<TodoCommentDescriptor> commentDescriptors, SyntacticDocument document, SyntaxTrivia trivia, List<TodoComment> todoList)
        {
            if (PreprocessorHasComment(trivia))
            {
                var message = trivia.ToFullString();

                var index = message.IndexOf(SingleLineCommentPrefix);
                var start = trivia.FullSpan.Start + index;

                AppendTodoCommentInfoFromSingleLine(commentDescriptors, document, message.Substring(index), start, todoList);
                return;
            }

            if (IsSingleLineComment(trivia))
            {
                ProcessMultilineComment(commentDescriptors, document, trivia, postfixLength: 0, todoList: todoList);
                return;
            }

            if (IsMultilineComment(trivia))
            {
                ProcessMultilineComment(commentDescriptors, document, trivia, s_multilineCommentPostfixLength, todoList);
                return;
            }

            throw ExceptionUtilities.Unreachable;
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:27,代码来源:CSharpTodoCommentIncrementalAnalyzerProvider.cs


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