本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax.GetLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# NameSyntax.GetLeadingTrivia方法的具体用法?C# NameSyntax.GetLeadingTrivia怎么用?C# NameSyntax.GetLeadingTrivia使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.NameSyntax
的用法示例。
在下文中一共展示了NameSyntax.GetLeadingTrivia方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryReduceAttributeSuffix
private static bool TryReduceAttributeSuffix(
NameSyntax name,
SyntaxToken identifierToken,
SemanticModel semanticModel,
out TypeSyntax replacementNode,
out TextSpan issueSpan,
CancellationToken cancellationToken)
{
issueSpan = default(TextSpan);
replacementNode = default(TypeSyntax);
// we can try to remove the Attribute suffix if this is the attribute name
if (SyntaxFacts.IsAttributeName(name))
{
if (name.Parent.Kind() == SyntaxKind.Attribute || name.IsRightSideOfDotOrColonColon())
{
const string AttributeName = "Attribute";
// an attribute that should keep it (unnecessary "Attribute" suffix should be annotated with a DontSimplifyAnnotation
if (identifierToken.ValueText != AttributeName && identifierToken.ValueText.EndsWith(AttributeName, StringComparison.Ordinal) && !identifierToken.HasAnnotation(SimplificationHelpers.DontSimplifyAnnotation))
{
// weird. the semantic model is able to bind attribute syntax like "[as()]" although it's not valid code.
// so we need another check for keywords manually.
var newAttributeName = identifierToken.ValueText.Substring(0, identifierToken.ValueText.Length - 9);
if (SyntaxFacts.GetKeywordKind(newAttributeName) != SyntaxKind.None)
{
return false;
}
// if this attribute name in source contained unicode escaping, we will loose it now
// because there is no easy way to determine the substring from identifier->ToString()
// which would be needed to pass to SyntaxFactory.Identifier
// The result is an unescaped unicode character in source.
// once we remove the Attribute suffix, we can't use an escaped identifier
var newIdentifierToken = identifierToken.CopyAnnotationsTo(
SyntaxFactory.Identifier(
identifierToken.LeadingTrivia,
newAttributeName,
identifierToken.TrailingTrivia));
replacementNode = SyntaxFactory.IdentifierName(newIdentifierToken)
.WithLeadingTrivia(name.GetLeadingTrivia());
issueSpan = new TextSpan(identifierToken.Span.End - 9, 9);
return true;
}
}
}
return false;
}