本文整理汇总了C#中SyntaxTrivia.CSharpKind方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxTrivia.CSharpKind方法的具体用法?C# SyntaxTrivia.CSharpKind怎么用?C# SyntaxTrivia.CSharpKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxTrivia
的用法示例。
在下文中一共展示了SyntaxTrivia.CSharpKind方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnTouchedNoisyCharacter
private bool OnTouchedNoisyCharacter(SyntaxTrivia trivia)
{
if (trivia.IsElastic() ||
trivia.CSharpKind() == SyntaxKind.WhitespaceTrivia ||
trivia.CSharpKind() == SyntaxKind.EndOfLineTrivia)
{
return false;
}
this.touchedNoisyCharacterOnCurrentLine = true;
this.hasTrailingSpace = false;
return false;
}
示例2: ClassifyPreprocessorTrivia
private void ClassifyPreprocessorTrivia(SyntaxTrivia trivia, bool allowComments)
{
if (allowComments && trivia.CSharpKind() == SyntaxKind.SingleLineCommentTrivia)
{
AddClassification(trivia, ClassificationTypeNames.Comment);
}
else
{
AddClassification(trivia, ClassificationTypeNames.PreprocessorText);
}
}
示例3: OnRegion
private bool OnRegion(SyntaxTrivia trivia, int currentIndex)
{
if (trivia.CSharpKind() != SyntaxKind.RegionDirectiveTrivia &&
trivia.CSharpKind() != SyntaxKind.EndRegionDirectiveTrivia)
{
return false;
}
if (!this.UseIndentation)
{
return true;
}
if (indentation != this.context.GetBaseIndentation(trivia.SpanStart))
{
return true;
}
ResetStateAfterNewLine(currentIndex);
return false;
}
示例4: OnPreprocessor
private bool OnPreprocessor(SyntaxTrivia trivia, int currentIndex)
{
if (!SyntaxFacts.IsPreprocessorDirective(trivia.CSharpKind()))
{
return false;
}
if (!this.UseIndentation)
{
return true;
}
// preprocessor must be at from column 0
if (this.indentation != 0)
{
return true;
}
ResetStateAfterNewLine(currentIndex);
return false;
}
示例5: OnEndOfLine
private bool OnEndOfLine(SyntaxTrivia trivia, int currentIndex)
{
if (trivia.CSharpKind() != SyntaxKind.EndOfLineTrivia)
{
return false;
}
// end of line trivia right after whitespace trivia
if (this.hasTrailingSpace)
{
// has trailing whitespace
return true;
}
// empty line with spaces. remove it.
if (this.indentation > 0 && !this.touchedNoisyCharacterOnCurrentLine)
{
return true;
}
ResetStateAfterNewLine(currentIndex);
return false;
}
示例6: OnSkippedTokensOrText
private bool OnSkippedTokensOrText(SyntaxTrivia trivia)
{
if (trivia.CSharpKind() != SyntaxKind.SkippedTokensTrivia &&
trivia.CSharpKind() != SyntaxKind.PreprocessingMessageTrivia)
{
return false;
}
return Contract.FailWithReturn<bool>("This can't happen");
}
示例7: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
if (trivia.HasStructure)
Visit(trivia.GetStructure());
switch (trivia.CSharpKind())
{
case SyntaxKind.MultiLineCommentTrivia:
case SyntaxKind.SingleLineCommentTrivia:
case SyntaxKind.SingleLineDocumentationCommentTrivia:
case SyntaxKind.MultiLineDocumentationCommentTrivia:
case SyntaxKind.DocumentationCommentExteriorTrivia:
Mark(trivia, "comment"); break;
case SyntaxKind.EndOfLineTrivia:
case SyntaxKind.WhitespaceTrivia:
Mark(trivia, "whitespace"); break;
case SyntaxKind.RegionDirectiveTrivia:
Mark(trivia, "begin-region"); break;
case SyntaxKind.EndRegionDirectiveTrivia:
Mark(trivia, "end-region"); break;
case SyntaxKind.DisabledTextTrivia:
Mark(trivia, "disabled-text"); break;
}
}
示例8: OnWhitespace
private bool OnWhitespace(SyntaxTrivia trivia)
{
if (trivia.CSharpKind() != SyntaxKind.WhitespaceTrivia)
{
return false;
}
// there was noisy char after end of line trivia
if (!this.UseIndentation || this.touchedNoisyCharacterOnCurrentLine)
{
this.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;
}
this.indentation += text.ConvertTabToSpace(this.optionSet.GetOption(FormattingOptions.TabSize, LanguageNames.CSharp), this.indentation, text.Length);
return false;
}
示例9: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
cancellationToken.ThrowIfCancellationRequested();
if (IsSyntacticallyFilteredOut(trivia.FullSpan))
{
return;
}
if (!IsValidLocation && SyntaxFacts.IsDocumentationCommentTrivia(trivia.CSharpKind()))
{
int start = trivia.Position; // FullSpan start to include /** or ///
const int length = 1; //Match dev11: span is just one character
diagnostics.Add(ErrorCode.WRN_UnprocessedXMLComment, new SourceLocation(trivia.SyntaxTree, new TextSpan(start, length)));
}
base.VisitTrivia(trivia);
}
示例10: IsWhitespace
private bool IsWhitespace(SyntaxTrivia trivia)
{
return trivia.CSharpKind() == SyntaxKind.WhitespaceTrivia
|| trivia.CSharpKind() == SyntaxKind.EndOfLineTrivia;
}
示例11: ClassifyTrivia
private void ClassifyTrivia(SyntaxTrivia trivia)
{
if (trivia.CSharpKind() == SyntaxKind.SingleLineCommentTrivia || trivia.CSharpKind() == SyntaxKind.MultiLineCommentTrivia)
{
AddClassification(trivia, ClassificationTypeNames.Comment);
}
else if (trivia.CSharpKind() == SyntaxKind.DisabledTextTrivia)
{
AddClassification(trivia, ClassificationTypeNames.ExcludedCode);
}
else if (trivia.CSharpKind() == SyntaxKind.SkippedTokensTrivia)
{
ClassifySkippedTokens((SkippedTokensTriviaSyntax)trivia.GetStructure());
}
else if (trivia.IsDocComment())
{
ClassifyDocumentationComment((DocumentationCommentTriviaSyntax)trivia.GetStructure());
}
else if (trivia.CSharpKind() == SyntaxKind.DocumentationCommentExteriorTrivia)
{
AddClassification(trivia, ClassificationTypeNames.XmlDocCommentDelimiter);
}
else if (SyntaxFacts.IsPreprocessorDirective(trivia.CSharpKind()))
{
ClassifyPreprocessorDirective((DirectiveTriviaSyntax)trivia.GetStructure());
}
}
示例12: VisitTrivia
public override void VisitTrivia(SyntaxTrivia trivia)
{
bool isDocComment = SyntaxFacts.IsDocumentationCommentTrivia(trivia.CSharpKind());
if (isDocComment ||
trivia.CSharpKind() == SyntaxKind.SingleLineCommentTrivia ||
trivia.CSharpKind() == SyntaxKind.MultiLineCommentTrivia)
{
Results.AppendLine();
Results.Append(trivia.ToFullString().Trim());
Results.Append(" (Parent Token: ");
Results.Append(trivia.Token.CSharpKind());
Results.Append(")");
if (isDocComment)
{
// Trivia for xml documentation comments have addditional 'structure'
// available under a child DocumentationCommentSyntax.
Assert.IsTrue(trivia.HasStructure);
var documentationComment =
(DocumentationCommentTriviaSyntax)trivia.GetStructure();
Assert.IsTrue(documentationComment.ParentTrivia == trivia);
Results.Append(" (Structured)");
}
}
base.VisitTrivia(trivia);
}
示例13: VisitTrivia
public override SyntaxTrivia VisitTrivia(SyntaxTrivia trivia)
{
var comment = trivia.ToString();
if (trivia.CSharpKind() == 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.CSharpKind() == 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);
}
示例14: AnalyzeWhitespacesInTrivia
private static void AnalyzeWhitespacesInTrivia(SyntaxTrivia trivia, ref AnalysisResult result)
{
// trivia already has text. getting text should be noop
Debug.Assert(trivia.CSharpKind() == SyntaxKind.WhitespaceTrivia);
Debug.Assert(trivia.Width() == trivia.FullWidth());
int space = 0;
int tab = 0;
int unknownWhitespace = 0;
var text = trivia.ToString();
for (int i = 0; i < trivia.Width(); i++)
{
if (text[i] == ' ')
{
space++;
}
else if (text[i] == '\t')
{
if (result.Space > 0)
{
result.HasTabAfterSpace = true;
}
tab++;
}
else
{
unknownWhitespace++;
}
}
// set result
result.Space += space;
result.Tab += tab;
result.HasUnknownWhitespace |= unknownWhitespace > 0;
result.TreatAsElastic |= trivia.IsElastic();
}