本文整理汇总了C#中ExpressionSyntax.WithLeadingTrivia方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.WithLeadingTrivia方法的具体用法?C# ExpressionSyntax.WithLeadingTrivia怎么用?C# ExpressionSyntax.WithLeadingTrivia使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.WithLeadingTrivia方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FullyQualifyIdentifierName
private ExpressionSyntax FullyQualifyIdentifierName(
ISymbol symbol,
ExpressionSyntax rewrittenNode,
ExpressionSyntax originalNode,
bool replaceNode,
bool isInsideCref,
bool omitLeftHandSide)
{
Debug.Assert(!replaceNode || rewrittenNode.Kind() == SyntaxKind.IdentifierName);
//// TODO: use and expand Generate*Syntax(isymbol) to not depend on symbol display any more.
//// See GenerateExpressionSyntax();
var result = rewrittenNode;
// only if this symbol has a containing type or namespace there is work for us to do.
if (replaceNode || symbol.ContainingType != null || symbol.ContainingNamespace != null)
{
ImmutableArray<SymbolDisplayPart> displayParts;
ExpressionSyntax left = null;
// we either need to create an AliasQualifiedName if the symbol is directly contained in the global namespace,
// otherwise it a QualifiedName.
if (!replaceNode && symbol.ContainingType == null && symbol.ContainingNamespace.IsGlobalNamespace)
{
return rewrittenNode.CopyAnnotationsTo(
SyntaxFactory.AliasQualifiedName(
SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)),
(SimpleNameSyntax)rewrittenNode.WithLeadingTrivia(null))
.WithLeadingTrivia(rewrittenNode.GetLeadingTrivia()));
}
displayParts = replaceNode
? symbol.ToDisplayParts(s_typeNameFormatWithGenerics)
: (symbol.ContainingType ?? (ISymbol)symbol.ContainingNamespace).ToDisplayParts(s_typeNameFormatWithGenerics);
rewrittenNode = TryAddTypeArgumentToIdentifierName(rewrittenNode, symbol);
// Replaces the '<' token with the '{' token since we are inside crefs
rewrittenNode = TryReplaceAngleBracesWithCurlyBraces(rewrittenNode, isInsideCref);
result = rewrittenNode;
if (!omitLeftHandSide)
{
left = SyntaxFactory.ParseTypeName(displayParts.ToDisplayString());
// Replaces the '<' token with the '{' token since we are inside crefs
left = TryReplaceAngleBracesWithCurlyBraces(left, isInsideCref);
if (replaceNode)
{
return left
.WithLeadingTrivia(rewrittenNode.GetLeadingTrivia())
.WithTrailingTrivia(rewrittenNode.GetTrailingTrivia());
}
// now create syntax for the combination of left and right syntax, or a simple replacement in case of an identifier
var parent = originalNode.Parent;
var leadingTrivia = rewrittenNode.GetLeadingTrivia();
rewrittenNode = rewrittenNode.WithLeadingTrivia(null);
switch (parent.Kind())
{
case SyntaxKind.QualifiedName:
var qualifiedParent = (QualifiedNameSyntax)parent;
result = rewrittenNode.CopyAnnotationsTo(
SyntaxFactory.QualifiedName(
(NameSyntax)left,
(SimpleNameSyntax)rewrittenNode));
break;
case SyntaxKind.SimpleMemberAccessExpression:
var memberAccessParent = (MemberAccessExpressionSyntax)parent;
result = rewrittenNode.CopyAnnotationsTo(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
left,
(SimpleNameSyntax)rewrittenNode));
break;
default:
Debug.Assert(rewrittenNode is SimpleNameSyntax);
if (SyntaxFacts.IsInNamespaceOrTypeContext(originalNode))
{
var right = (SimpleNameSyntax)rewrittenNode;
result = rewrittenNode.CopyAnnotationsTo(SyntaxFactory.QualifiedName((NameSyntax)left, right.WithAdditionalAnnotations(Simplifier.SpecialTypeAnnotation)));
}
else if (originalNode.Parent is CrefSyntax)
{
var right = (SimpleNameSyntax)rewrittenNode;
result = rewrittenNode.CopyAnnotationsTo(SyntaxFactory.QualifiedName((NameSyntax)left, right));
}
else
{
//.........这里部分代码省略.........