• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SyntaxTrivia类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SyntaxTrivia类属于命名空间,在下文中一共展示了SyntaxTrivia类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


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


示例17: CollectBlockSpans

 public override void CollectBlockSpans(
     Document document,
     SyntaxTrivia trivia,
     ArrayBuilder<BlockSpan> spans,
     CancellationToken cancellationToken)
 {
     CollectBlockSpans(trivia.SyntaxTree, trivia, spans, cancellationToken);
 }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:8,代码来源:DisabledTextTriviaStructureProvider.cs


示例18: CollectOutliningSpans

 public override void CollectOutliningSpans(
     Document document,
     SyntaxTrivia trivia,
     List<OutliningSpan> spans,
     CancellationToken cancellationToken)
 {
     CollectOutliningSpans(trivia.SyntaxTree, trivia, spans, cancellationToken);
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:8,代码来源:DisabledTextTriviaOutliner.cs


示例19: Create

 internal static StructuredTriviaSyntax Create(SyntaxTrivia trivia)
 {
     var node = trivia.UnderlyingNode;
     var parent = (CSharpSyntaxNode)trivia.Token.Parent;
     var position = trivia.Position;
     var red = (StructuredTriviaSyntax)node.CreateRed(parent, position);
     red.parent = trivia;
     return red;
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:9,代码来源:StructuredTriviaSyntax.cs


示例20: Add

        public void Add(SyntaxTrivia[] items, int offset, int length)
        {
            if (nodes == null || count + length > nodes.Length)
            {
                this.Grow(count + length);
            }

            Array.Copy(items, offset, nodes, count, length);
            count += length;
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:10,代码来源:SyntaxTriviaListBuilder.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SyntaxTriviaList类代码示例发布时间:2022-05-24
下一篇:
C# SyntaxTreeAnalysisContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap