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


C# SyntaxTrivia.ToString方法代码示例

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


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

示例1: VisitTrivia

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

示例2: HandleMultiLineComment

        private static void HandleMultiLineComment(SyntaxTreeAnalysisContext context, SyntaxTrivia multiLineComment)
        {
            var nodeText = multiLineComment.ToString();

            // We remove the /* and the */ and determine if the comment has any content.
            var commentText = nodeText.Substring(2, nodeText.Length - 4);

            if (string.IsNullOrWhiteSpace(commentText))
            {
                var diagnostic = Diagnostic.Create(Descriptor, multiLineComment.GetLocation());
                context.ReportDiagnostic(diagnostic);
            }
        }
开发者ID:Noryoko,项目名称:StyleCopAnalyzers,代码行数:13,代码来源:SA1120CommentsMustContainText.cs

示例3: ClassifyExteriorTrivia

        private void ClassifyExteriorTrivia(SyntaxTrivia trivia)
        {
            // Note: The exterior trivia can contain whitespace (usually leading) and we want to avoid classifying it.
            // However, meaningful exterior trivia can also have an undetermined length in the case of
            // multiline doc comments.

            // For example:
            //
            //     /**<summary>
            //      ********* Foo
            //      ******* </summary>*/

            // PERFORMANCE:
            // While the call to SyntaxTrivia.ToString() looks like an allocation, it isn't.
            // The SyntaxTrivia green node holds the string text of the trivia in a field and ToString()
            // just returns a reference to that.
            var text = trivia.ToString();

            int? spanStart = null;

            for (var index = 0; index < text.Length; index++)
            {
                var ch = text[index];

                if (spanStart != null && char.IsWhiteSpace(ch))
                {
                    var span = TextSpan.FromBounds(spanStart.Value, spanStart.Value + index);
                    AddClassification(span, ClassificationTypeNames.XmlDocCommentDelimiter);
                    spanStart = null;
                }
                else if (spanStart == null && !char.IsWhiteSpace(ch))
                {
                    spanStart = trivia.Span.Start + index;
                }
            }

            // Add a final classification if we hadn't encountered anymore whitespace at the end.
            if (spanStart != null)
            {
                var span = TextSpan.FromBounds(spanStart.Value, trivia.Span.End);
                AddClassification(span, ClassificationTypeNames.XmlDocCommentDelimiter);
            }
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:43,代码来源:Worker_DocumentationComments.cs

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

示例5: ExtractMarkDownFromComment

		public static SlideBlock ExtractMarkDownFromComment(SyntaxTrivia comment)
		{
			int identation = comment.SyntaxTree.GetLineSpan(comment.FullSpan).StartLinePosition.Character;
			string[] commentLines = comment.ToString().SplitToLines();
			if (commentLines.First().EndsWith("tex"))
				return new TexBlock(commentLines.Skip(1).Take(commentLines.Length - 2).ToArray());
			return new MdBlock(GetCommentContent(commentLines, identation));
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:8,代码来源:BlocksBuilder.cs

示例6: ProcessCommentTrivia

 private void ProcessCommentTrivia(SyntaxTrivia trivia, List<TriviaSyntaxElement> targetedElements, bool isSingleLine)
 {
     targetedElements.Add(new CommentTriviaSyntaxElement(trivia.ToString()));
 }
开发者ID:pgrefviau,项目名称:SourceMaster,代码行数:4,代码来源:FileSyntaxWalker.cs

示例7: OnWhitespace

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

                // there was noisy char after end of line trivia
                if (!this.UseIndentation || _touchedNoisyCharacterOnCurrentLine)
                {
                    _hasTrailingSpace = true;
                    return false;
                }

                // right after end of line trivia. calculate indentation for current line
                Debug.Assert(trivia.ToString() == trivia.ToFullString());
                var text = trivia.ToString();

                // if text contains tab, we will give up perf optimization and use more expensive one to see whether we need to replace this trivia
                if (text.IndexOf('\t') >= 0)
                {
                    return true;
                }

                _indentation += text.ConvertTabToSpace(_optionSet.GetOption(FormattingOptions.TabSize, LanguageNames.CSharp), _indentation, text.Length);

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

示例8: GetUncommentBody

		private static string GetUncommentBody(SyntaxTrivia c)
		{
			var comment = c.ToString().Substring(uncommentPrefix.Length);
			return comment.Substring(0, comment.Length - 2).RemoveCommonNesting();
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:5,代码来源:ExerciseBuilder.cs

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

示例10: VisitTrivia

			public override void VisitTrivia (SyntaxTrivia trivia)
			{
				cancellationToken.ThrowIfCancellationRequested ();
				if (trivia.IsKind (SyntaxKind.SingleLineCommentTrivia) || 
					trivia.IsKind (SyntaxKind.MultiLineCommentTrivia) || 
					trivia.IsKind (SyntaxKind.SingleLineDocumentationCommentTrivia)) {
					var trimmedContent = trivia.ToString ().TrimStart ('/', ' ', '*');
					foreach (string tag in tagComments) {
						if (!trimmedContent.StartsWith (tag, StringComparison.Ordinal))
							continue;
						var loc = trivia.GetLocation ().GetLineSpan ();
						Tags.Add (new Tag (tag, trimmedContent, new DocumentRegion (loc.StartLinePosition, loc.EndLinePosition)));
						break;
					}
				}
			}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:16,代码来源:CSharpParsedDocument.cs

示例11: GetRegion

			static DocumentRegion GetRegion (SyntaxTrivia trivia)
			{
				var fullSpan = trivia.FullSpan;
				var text = trivia.ToString ();
				if (text.Length > 2) {
					if (text [text.Length - 2] == '\r' && text [text.Length - 1] == '\n')
						fullSpan = new Microsoft.CodeAnalysis.Text.TextSpan (fullSpan.Start, fullSpan.Length - 2);
					else if (NewLine.IsNewLine (text [text.Length - 1]))
						fullSpan = new Microsoft.CodeAnalysis.Text.TextSpan (fullSpan.Start, fullSpan.Length - 1);
				}
				try {
					var lineSpan = trivia.SyntaxTree.GetLineSpan (fullSpan);
					return (DocumentRegion)lineSpan;
				} catch (Exception) {
					return DocumentRegion.Empty;
				}
			}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:17,代码来源:CSharpParsedDocument.cs

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

示例13: IsDocumentationCommentTriviaAndNotProperXML

 private static bool IsDocumentationCommentTriviaAndNotProperXML(SyntaxTrivia trivia)
 {
     return (trivia.Kind() == SyntaxKind.DocumentationCommentTrivia &&
         ( trivia.ToString()).IsValidXml() == false);
 }
开发者ID:joymon,项目名称:joyful-visualstudio,代码行数:5,代码来源:VBCommentedCodeRemover.cs

示例14: VisitTrivia

        public override void VisitTrivia(SyntaxTrivia trivia)
        {
            var atch = new AnnotatedCodeChunk { TextValue = trivia.ToString() };

            var triviaKind = trivia.Kind();
            if (triviaKind == SyntaxKind.SingleLineCommentTrivia
                || triviaKind == SyntaxKind.MultiLineCommentTrivia
                || triviaKind == SyntaxKind.XmlComment)
            {
                atch.CodeType = CodeType.Comment;
            }

            AddItcAction(atch);

            base.VisitTrivia(trivia);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:16,代码来源:ReportingCSharpSyntaxWalker.cs

示例15: QuoteTrivia

    private ApiCall QuoteTrivia(SyntaxTrivia syntaxTrivia)
    {
        string factoryMethodName = "SyntaxFactory.Trivia";
        string text = syntaxTrivia.ToString();
        if (syntaxTrivia.FullSpan.Length == 0 ||
            (syntaxTrivia.Kind() == SyntaxKind.WhitespaceTrivia && UseDefaultFormatting))
        {
            return null;
        }

        PropertyInfo triviaFactoryProperty = null;
        if (triviaFactoryProperties.TryGetValue(syntaxTrivia.ToString(), out triviaFactoryProperty) &&
            ((SyntaxTrivia)triviaFactoryProperty.GetValue(null)).Kind() == syntaxTrivia.Kind())
        {
            if (UseDefaultFormatting)
            {
                return null;
            }

            return new ApiCall(null, "SyntaxFactory." + triviaFactoryProperty.Name);
        }

        if (!string.IsNullOrEmpty(text) &&
            string.IsNullOrWhiteSpace(text) &&
            syntaxTrivia.Kind() == SyntaxKind.WhitespaceTrivia)
        {
            if (UseDefaultFormatting)
            {
                return null;
            }

            factoryMethodName = "SyntaxFactory.Whitespace";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.SingleLineCommentTrivia ||
            syntaxTrivia.Kind() == SyntaxKind.MultiLineCommentTrivia)
        {
            factoryMethodName = "SyntaxFactory.Comment";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.PreprocessingMessageTrivia)
        {
            factoryMethodName = "SyntaxFactory.PreprocessingMessage";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.DisabledTextTrivia)
        {
            factoryMethodName = "SyntaxFactory.DisabledText";
        }

        if (syntaxTrivia.Kind() == SyntaxKind.DocumentationCommentExteriorTrivia)
        {
            factoryMethodName = "SyntaxFactory.DocumentationCommentExterior";
        }

        object argument = "@\"" + Escape(syntaxTrivia.ToString()) + "\"";

        if (syntaxTrivia.HasStructure)
        {
            argument = QuoteNode(syntaxTrivia.GetStructure(), "Structure");
        }

        return new ApiCall(null, factoryMethodName, CreateArgumentList(argument));
    }
开发者ID:SkightTeam,项目名称:RoslynQuoter,代码行数:64,代码来源:Quoter.cs


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