本文整理汇总了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());
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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));
}
示例6: ProcessCommentTrivia
private void ProcessCommentTrivia(SyntaxTrivia trivia, List<TriviaSyntaxElement> targetedElements, bool isSingleLine)
{
targetedElements.Add(new CommentTriviaSyntaxElement(trivia.ToString()));
}
示例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;
}
示例8: GetUncommentBody
private static string GetUncommentBody(SyntaxTrivia c)
{
var comment = c.ToString().Substring(uncommentPrefix.Length);
return comment.Substring(0, comment.Length - 2).RemoveCommonNesting();
}
示例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;
}
示例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;
}
}
}
示例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;
}
}
示例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;
}
示例13: IsDocumentationCommentTriviaAndNotProperXML
private static bool IsDocumentationCommentTriviaAndNotProperXML(SyntaxTrivia trivia)
{
return (trivia.Kind() == SyntaxKind.DocumentationCommentTrivia &&
( trivia.ToString()).IsValidXml() == false);
}
示例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);
}
示例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));
}