本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax类的典型用法代码示例。如果您正苦于以下问题:C# SimpleNameSyntax类的具体用法?C# SimpleNameSyntax怎么用?C# SimpleNameSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleNameSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了SimpleNameSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateInvocationExpression
public static InvocationExpressionSyntax CreateInvocationExpression(ExpressionSyntax sourceExpression, SimpleNameSyntax methodName, ArgumentListSyntax argumentList) =>
SyntaxFactory.InvocationExpression(
SyntaxFactory.MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
sourceExpression,
methodName),
argumentList);
开发者ID:JeanLLopes,项目名称:code-cracker,代码行数:7,代码来源:CallExtensionMethodAsExtensionCodeFixProvider.cs
示例2: BindRangeVariable
protected override BoundExpression BindRangeVariable(SimpleNameSyntax node, RangeVariableSymbol qv, DiagnosticBag diagnostics)
{
Debug.Assert(!qv.IsTransparent);
BoundExpression translation;
ImmutableArray<string> path;
if (_rangeVariableMap.TryGetValue(qv, out path))
{
if (path.IsEmpty)
{
// the range variable maps directly to a use of the parameter of that name
var value = base.parameterMap[qv.Name];
Debug.Assert(value.Count == 1);
translation = new BoundParameter(node, value.Single()) { WasCompilerGenerated = true };
}
else
{
// if the query variable map for this variable is non empty, we always start with the current
// lambda's first parameter, which is a transparent identifier.
Debug.Assert(base.lambdaSymbol.Parameters[0].Name.StartsWith(transparentIdentifierPrefix));
translation = new BoundParameter(node, base.lambdaSymbol.Parameters[0]) { WasCompilerGenerated = true };
for (int i = path.Length - 1; i >= 0; i--)
{
var nextField = path[i];
translation = SelectField(node, translation, nextField, diagnostics);
translation.WasCompilerGenerated = true;
}
}
return new BoundRangeVariable(node, qv, translation, translation.Type);
}
return base.BindRangeVariable(node, qv, diagnostics);
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:34,代码来源:Binder.WithQueryLambdaParametersBinder.cs
示例3: SelectField
private BoundExpression SelectField(SimpleNameSyntax node, BoundExpression receiver, string name, DiagnosticBag diagnostics)
{
var receiverType = receiver.Type as NamedTypeSymbol;
if ((object)receiverType == null || !receiverType.IsAnonymousType)
{
// We only construct transparent query variables using anonymous types, so if we're trying to navigate through
// some other type, we must have some hinky query API where the types don't match up as expected.
// We should report this as an error of some sort.
// TODO: DevDiv #737822 - reword error message and add test.
var info = new CSDiagnosticInfo(ErrorCode.ERR_UnsupportedTransparentIdentifierAccess, name, receiver.ExpressionSymbol ?? receiverType);
Error(diagnostics, info, node);
return new BoundBadExpression(
node,
LookupResultKind.Empty,
ImmutableArray.Create<Symbol>(receiver.ExpressionSymbol),
ImmutableArray.Create<BoundNode>(receiver),
new ExtendedErrorTypeSymbol(this.Compilation, "", 0, info));
}
LookupResult lookupResult = LookupResult.GetInstance();
LookupOptions options = LookupOptions.MustBeInstance;
HashSet<DiagnosticInfo> useSiteDiagnostics = null;
LookupMembersWithFallback(lookupResult, receiver.Type, name, 0, ref useSiteDiagnostics, basesBeingResolved: null, options: options);
diagnostics.Add(node, useSiteDiagnostics);
var result = BindMemberOfType(node, node, name, 0, receiver, default(SeparatedSyntaxList<TypeSyntax>), default(ImmutableArray<TypeSymbol>), lookupResult, BoundMethodGroupFlags.None, diagnostics);
result.WasCompilerGenerated = true;
lookupResult.Free();
return result;
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:30,代码来源:Binder.WithQueryLambdaParametersBinder.cs
示例4: GetCallerMethodSymbol
private static IMethodSymbol GetCallerMethodSymbol(SemanticModel semanticModel, SimpleNameSyntax name, int argumentsCount)
{
var symbolInfo = semanticModel.GetSymbolInfo(name);
return symbolInfo.Symbol as IMethodSymbol ??
symbolInfo
.CandidateSymbols
.OfType<IMethodSymbol>()
.FirstOrDefault(s => s.Parameters.Length == argumentsCount + 1);
}
开发者ID:rsaladrigas,项目名称:code-cracker,代码行数:9,代码来源:CallExtensionMethodAsExtensionAnalyzer.cs
示例5: OtherMethodExists
private static bool OtherMethodExists(InvocationExpressionSyntax invocation, SimpleNameSyntax nameToCheck, SemanticModel semanticModel)
{
var otherExpression = ((MemberAccessExpressionSyntax)invocation.Expression).WithName(nameToCheck).WithAdditionalAnnotations(speculativeAnnotation);
var statement = invocation.FirstAncestorOrSelfThatIsAStatement();
var otherStatement = statement.ReplaceNode(invocation.Expression, otherExpression);
SemanticModel speculativeModel;
if (!semanticModel.TryGetSpeculativeSemanticModel(statement.SpanStart, otherStatement, out speculativeModel)) return false;
var otherInvocationSymbol = speculativeModel.GetSymbolInfo(speculativeModel.SyntaxTree.GetRoot().GetAnnotatedNodes(speculativeAnnotationDescription).First());
return otherInvocationSymbol.Symbol != null;
}
开发者ID:transformersprimeabcxyz,项目名称:code-cracker,代码行数:10,代码来源:ChangeAnyToAllAnalyzer.cs
示例6: IsReference
private bool IsReference(SimpleNameSyntax name)
{
if (name.Identifier.ValueText != _variableDeclarator.Identifier.ValueText)
{
return false;
}
var symbol = _semanticModel.GetSymbolInfo(name).Symbol;
return symbol != null
&& symbol.Equals(_localSymbol);
}
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:11,代码来源:InlineTemporaryCodeRefactoringProvider.ReferenceRewriter.cs
示例7: GetTransformedDocumentAsync
private static Task<Document> GetTransformedDocumentAsync(Document document, SyntaxNode root, SimpleNameSyntax node)
{
var qualifiedExpression =
SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, ThisExpressionSyntax, node.WithoutTrivia().WithoutFormatting())
.WithTriviaFrom(node)
.WithoutFormatting();
var newSyntaxRoot = root.ReplaceNode(node, qualifiedExpression);
return Task.FromResult(document.WithSyntaxRoot(newSyntaxRoot));
}
开发者ID:JaRau,项目名称:StyleCopAnalyzers,代码行数:11,代码来源:SA1101CodeFixProvider.cs
示例8: From
public static TypeNameText From(SimpleNameSyntax syntax)
{
var identifier = syntax.Identifier.Text;
var typeArgs = string.Empty;
var genericName = syntax as GenericNameSyntax;
if (genericName != null && genericName.TypeArgumentList != null)
{
var count = genericName.TypeArgumentList.Arguments.Count;
identifier = $"\"{identifier}`{count}\"";
typeArgs = "<" + string.Join(",", genericName.TypeArgumentList.Arguments) + ">";
}
return new TypeNameText
{
Identifier = identifier,
TypeArguments = typeArgs
};
}
开发者ID:pierre3,项目名称:PlantUmlClassDiagramGenerator,代码行数:17,代码来源:TypeNameText.cs
示例9: IsSelectingADifferentMethod
private static bool IsSelectingADifferentMethod(IEnumerable<SyntaxNode> childNodes, SimpleNameSyntax methodName, SyntaxTree tree, IMethodSymbol methodSymbol, ExpressionSyntax invocationExpression, Compilation compilation)
{
var parameterExpressions = GetParameterExpressions(childNodes);
var firstArgument = parameterExpressions.FirstOrDefault();
var argumentList = CreateArgumentListSyntaxFrom(parameterExpressions.Skip(1));
var newInvocationStatement = CreateInvocationExpression(firstArgument, methodName, argumentList)
.WithAdditionalAnnotations(introduceExtensionMethodAnnotation);
var extensionMethodNamespaceUsingDirective = SyntaxFactory.UsingDirective(methodSymbol.ContainingNamespace.ToNameSyntax());
var speculativeRootWithExtensionMethod = tree.GetCompilationUnitRoot()
.ReplaceNode(invocationExpression, newInvocationStatement)
.AddUsings(extensionMethodNamespaceUsingDirective);
var speculativeModel = compilation.ReplaceSyntaxTree(tree, speculativeRootWithExtensionMethod.SyntaxTree)
.GetSemanticModel(speculativeRootWithExtensionMethod.SyntaxTree);
var speculativeInvocationStatement = speculativeRootWithExtensionMethod.SyntaxTree.GetCompilationUnitRoot().GetAnnotatedNodes(introduceExtensionMethodAnnotation).Single() as InvocationExpressionSyntax;
var speculativeExtensionMethodSymbol = speculativeModel.GetSymbolInfo(speculativeInvocationStatement.Expression).Symbol as IMethodSymbol;
var speculativeNonExtensionFormOfTheMethodSymbol = speculativeExtensionMethodSymbol?.GetConstructedReducedFrom();
return speculativeNonExtensionFormOfTheMethodSymbol == null || !speculativeNonExtensionFormOfTheMethodSymbol.Equals(methodSymbol);
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:18,代码来源:CallExtensionMethodAsExtensionAnalyzer.cs
示例10: IsSelectingADifferentMethod
private static bool IsSelectingADifferentMethod(IEnumerable<SyntaxNode> childNodes, SimpleNameSyntax methodName, SyntaxTree tree, IMethodSymbol methodSymbol, ExpressionSyntax invocationExpression, Compilation compilation)
{
var parameterExpressions = GetParameterExpressions(childNodes);
var firstArgument = parameterExpressions.FirstOrDefault();
var argumentList = CreateArgumentListSyntaxFrom(parameterExpressions.Skip(1));
var newInvocationStatement = CreateInvocationExpression(firstArgument, methodName, argumentList)
.WithAdditionalAnnotations(introduceExtensionMethodAnnotation);
var extensionMethodNamespaceUsingDirective = SyntaxFactory.UsingDirective(methodSymbol.ContainingNamespace.ToNameSyntax());
var speculativeRootWithExtensionMethod = tree.GetCompilationUnitRoot()
.ReplaceNode(invocationExpression, newInvocationStatement)
.AddUsings(extensionMethodNamespaceUsingDirective);
var speculativeTree = speculativeRootWithExtensionMethod.SyntaxTree;
var speculativeTreeOptions = (CSharpParseOptions)speculativeTree.Options;
var speculativeTreeWithCorrectLanguageVersion = speculativeTree.WithRootAndOptions(speculativeRootWithExtensionMethod, speculativeTreeOptions.WithLanguageVersion(((CSharpParseOptions)tree.Options).LanguageVersion));
var speculativeModel = compilation.ReplaceSyntaxTree(tree, speculativeTreeWithCorrectLanguageVersion)
.GetSemanticModel(speculativeTreeWithCorrectLanguageVersion);
var speculativeInvocationStatement = speculativeTreeWithCorrectLanguageVersion.GetCompilationUnitRoot().GetAnnotatedNodes(introduceExtensionMethodAnnotation).Single() as InvocationExpressionSyntax;
var speculativeExtensionMethodSymbol = speculativeModel.GetSymbolInfo(speculativeInvocationStatement.Expression).Symbol as IMethodSymbol;
var speculativeNonExtensionFormOfTheMethodSymbol = speculativeExtensionMethodSymbol?.GetConstructedReducedFrom();
return speculativeNonExtensionFormOfTheMethodSymbol == null || speculativeNonExtensionFormOfTheMethodSymbol.ToString() != methodSymbol.ToString();//can't compare equality, as speculative symbol might be different
}
开发者ID:julianosaless,项目名称:code-cracker,代码行数:21,代码来源:CallExtensionMethodAsExtensionAnalyzer.cs
示例11: IsInvocationWithDynamicArguments
private bool IsInvocationWithDynamicArguments(SimpleNameSyntax originalSimpleName, SemanticModel semanticModel)
{
var invocationExpression = originalSimpleName.Ancestors().OfType<InvocationExpressionSyntax>().FirstOrDefault();
// Check to see if this is the invocation Expression we wanted to work with
if (invocationExpression != null && invocationExpression.Expression.GetLastToken() == originalSimpleName.GetLastToken())
{
if (invocationExpression.ArgumentList != null)
{
foreach (var argument in invocationExpression.ArgumentList.Arguments)
{
if (argument != null && argument.Expression != null)
{
var typeinfo = semanticModel.GetTypeInfo(argument.Expression);
if (typeinfo.Type != null && typeinfo.Type.TypeKind == TypeKind.Dynamic)
{
return true;
}
}
}
}
}
return false;
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:25,代码来源:CSharpSimplificationService.Expander.cs
示例12: VisitSimpleName
private ExpressionSyntax VisitSimpleName(SimpleNameSyntax rewrittenSimpleName, SimpleNameSyntax originalSimpleName)
{
_cancellationToken.ThrowIfCancellationRequested();
// if this is "var", then do not process further
if (originalSimpleName.IsVar)
{
return rewrittenSimpleName;
}
var identifier = rewrittenSimpleName.Identifier;
ExpressionSyntax newNode = rewrittenSimpleName;
var isInsideCref = originalSimpleName.AncestorsAndSelf(ascendOutOfTrivia: true).Any(n => n is CrefSyntax);
////
//// 1. if this identifier is an alias, we'll expand it here and replace the node completely.
////
if (!SyntaxFacts.IsAliasQualifier(originalSimpleName))
{
var aliasInfo = _semanticModel.GetAliasInfo(originalSimpleName, _cancellationToken);
if (aliasInfo != null)
{
var aliasTarget = aliasInfo.Target;
if (aliasTarget.IsNamespace() && ((INamespaceSymbol)aliasTarget).IsGlobalNamespace)
{
return rewrittenSimpleName;
}
// if the enclosing expression is a typeof expression that already contains open type we cannot
// we need to insert an open type as well.
var typeOfExpression = originalSimpleName.GetAncestor<TypeOfExpressionSyntax>();
if (typeOfExpression != null && IsTypeOfUnboundGenericType(_semanticModel, typeOfExpression))
{
aliasTarget = ((INamedTypeSymbol)aliasTarget).ConstructUnboundGenericType();
}
// the expanded form replaces the current identifier name.
var replacement = FullyQualifyIdentifierName(
aliasTarget,
newNode,
originalSimpleName,
replaceNode: true,
isInsideCref: isInsideCref,
omitLeftHandSide: false)
.WithAdditionalAnnotations(Simplifier.Annotation);
// We replace the simple name completely, so we can't continue and rename the token
// with a RenameLocationAnnotation.
// There's also no way of removing annotations, so we just add a DoNotRenameAnnotation.
if (replacement.Kind() == SyntaxKind.AliasQualifiedName)
{
var qualifiedReplacement = (AliasQualifiedNameSyntax)replacement;
var newIdentifier = identifier.CopyAnnotationsTo(qualifiedReplacement.Name.Identifier);
if (_annotationForReplacedAliasIdentifier != null)
{
newIdentifier = newIdentifier.WithAdditionalAnnotations(_annotationForReplacedAliasIdentifier);
}
var aliasAnnotationInfo = AliasAnnotation.Create(aliasInfo.Name);
newIdentifier = newIdentifier.WithAdditionalAnnotations(aliasAnnotationInfo);
replacement = replacement.ReplaceNode(
qualifiedReplacement.Name,
qualifiedReplacement.Name.WithIdentifier(newIdentifier));
replacement = newNode.CopyAnnotationsTo(replacement);
var firstReplacementToken = replacement.GetFirstToken(true, false, true, true);
var firstOriginalToken = originalSimpleName.GetFirstToken(true, false, true, true);
SyntaxToken tokenWithLeadingWhitespace;
if (TryAddLeadingElasticTriviaIfNecessary(firstReplacementToken, firstOriginalToken, out tokenWithLeadingWhitespace))
{
replacement = replacement.ReplaceToken(firstOriginalToken, tokenWithLeadingWhitespace);
}
replacement = AppendElasticTriviaIfNecessary(replacement, originalSimpleName);
return replacement;
}
if (replacement.Kind() == SyntaxKind.QualifiedName)
{
var qualifiedReplacement = (QualifiedNameSyntax)replacement;
var newIdentifier = identifier.CopyAnnotationsTo(qualifiedReplacement.Right.Identifier);
if (_annotationForReplacedAliasIdentifier != null)
{
newIdentifier = newIdentifier.WithAdditionalAnnotations(_annotationForReplacedAliasIdentifier);
}
var aliasAnnotationInfo = AliasAnnotation.Create(aliasInfo.Name);
newIdentifier = newIdentifier.WithAdditionalAnnotations(aliasAnnotationInfo);
//.........这里部分代码省略.........
开发者ID:RoryVL,项目名称:roslyn,代码行数:101,代码来源:CSharpSimplificationService.Expander.cs
示例13: TypeArgumentSymbolsPresentInName
private IList<ISymbol> TypeArgumentSymbolsPresentInName(SimpleNameSyntax simpleName)
{
List<ISymbol> typeArgumentSymbols = new List<ISymbol>();
var typeArgumentListSyntax = simpleName.DescendantNodesAndSelf().Where(n => n is TypeArgumentListSyntax);
foreach (var typeArgumentList in typeArgumentListSyntax)
{
var castedTypeArgument = (TypeArgumentListSyntax)typeArgumentList;
foreach (var typeArgument in castedTypeArgument.Arguments)
{
var symbol = _semanticModel.GetSymbolInfo(typeArgument).Symbol;
if (symbol != null && !typeArgumentSymbols.Contains(symbol))
{
typeArgumentSymbols.Add(symbol);
}
}
}
return typeArgumentSymbols;
}
开发者ID:RoryVL,项目名称:roslyn,代码行数:19,代码来源:CSharpSimplificationService.Expander.cs
示例14: ReplaceStaticCallWithExtionMethodCall
private static CompilationUnitSyntax ReplaceStaticCallWithExtionMethodCall(CompilationUnitSyntax root, InvocationExpressionSyntax staticInvocationExpression, ExpressionSyntax sourceExpression, SimpleNameSyntax methodName, ArgumentListSyntax argumentList)
{
var extensionInvocationExpression = CallExtensionMethodAsExtensionAnalyzer.CreateInvocationExpression(sourceExpression, methodName, argumentList)
.WithLeadingTrivia(staticInvocationExpression.GetLeadingTrivia());
return root.ReplaceNode(staticInvocationExpression, extensionInvocationExpression);
}
开发者ID:haroldhues,项目名称:code-cracker,代码行数:6,代码来源:CallExtensionMethodAsExtensionCodeFixProvider.cs
示例15: SimpleNameTranslation
public SimpleNameTranslation(SimpleNameSyntax syntax, SyntaxTranslation parent) : base(syntax, parent)
{
}
开发者ID:asthomas,项目名称:TypescriptSyntaxPaste,代码行数:3,代码来源:SimpleNameTranslation.cs
示例16: OtherMethodExists
private static bool OtherMethodExists(InvocationExpressionSyntax invocation, SimpleNameSyntax nameToCheck, SemanticModel semanticModel)
{
var otherExpression = CreateExpressionWithNewName(invocation, nameToCheck);
var statement = invocation.FirstAncestorOrSelfThatIsAStatement();
SemanticModel speculativeModel;
if (statement != null)
{
var otherStatement = statement.ReplaceNode(invocation.Expression, otherExpression);
if (!semanticModel.TryGetSpeculativeSemanticModel(statement.SpanStart, otherStatement, out speculativeModel)) return false;
}
else
{
var arrow = (ArrowExpressionClauseSyntax)invocation.FirstAncestorOfKind(SyntaxKind.ArrowExpressionClause);
if (arrow == null) return false;
var otherArrow = arrow.ReplaceNode(invocation.Expression, otherExpression);
if (!semanticModel.TryGetSpeculativeSemanticModel(arrow.SpanStart, otherArrow, out speculativeModel)) return false;
}
var symbol = speculativeModel.GetSymbolInfo(speculativeModel.SyntaxTree.GetRoot().GetAnnotatedNodes(speculativeAnnotationDescription).First()).Symbol;
return symbol != null;
}
开发者ID:Vossekop,项目名称:code-cracker,代码行数:20,代码来源:ChangeAnyToAllAnalyzer.cs
示例17: IsExplicitDelegateInvocation
private static bool IsExplicitDelegateInvocation(IMethodSymbol symbol, SimpleNameSyntax invokedMethodName)
{
var isDynamicInvocation = symbol.MethodKind == MethodKind.Ordinary &&
symbol.Name == "DynamicInvoke" &&
symbol.ReceiverType.OriginalDefinition.Is(KnownType.System_Delegate);
if (isDynamicInvocation)
{
return true;
}
return symbol.MethodKind == MethodKind.DelegateInvoke && invokedMethodName.Identifier.ValueText == "Invoke";
}
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:13,代码来源:UninvokedEventDeclaration.cs
示例18: ConvertIdentifier
SyntaxNode ConvertIdentifier(SimpleNameSyntax originalNode, SimpleNameSyntax withConvertedDescendants)
{
return SyntaxFactory.ParseName(originalNode.ToFullString().Replace("CSharp", "VB"));
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:4,代码来源:ConvertUnitTestToVB.cs
示例19: CreateExpressionWithNewName
public static ExpressionSyntax CreateExpressionWithNewName(InvocationExpressionSyntax invocation, SimpleNameSyntax nameToCheck)
{
var otherExpression = invocation.Expression.IsKind(SyntaxKind.MemberBindingExpression)
? (ExpressionSyntax)((MemberBindingExpressionSyntax)invocation.Expression).WithName(nameToCheck).WithAdditionalAnnotations(speculativeAnnotation)
//avoid this, already checked before: if (invocation.Expression.IsKind(SyntaxKind.SimpleMemberAccessExpression)):
: ((MemberAccessExpressionSyntax)invocation.Expression).WithName(nameToCheck).WithAdditionalAnnotations(speculativeAnnotation);
return otherExpression;
}
开发者ID:Vossekop,项目名称:code-cracker,代码行数:8,代码来源:ChangeAnyToAllAnalyzer.cs
示例20: TryReduceExtensionMethod
private static InvocationExpressionSyntax TryReduceExtensionMethod(InvocationExpressionSyntax node, SemanticModel semanticModel, InvocationExpressionSyntax rewrittenNode, SimpleNameSyntax expressionName)
{
var targetSymbol = semanticModel.GetSymbolInfo(expressionName);
if (targetSymbol.Symbol != null && targetSymbol.Symbol.Kind == SymbolKind.Method)
{
var targetMethodSymbol = (IMethodSymbol)targetSymbol.Symbol;
if (!targetMethodSymbol.IsReducedExtension())
{
var argumentList = node.ArgumentList;
var noOfArguments = argumentList.Arguments.Count;
if (noOfArguments > 0)
{
MemberAccessExpressionSyntax newMemberAccess = null;
var invocationExpressionNodeExpression = node.Expression;
if (node.Expression.CSharpKind() == SyntaxKind.SimpleMemberAccessExpression)
{
newMemberAccess = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, argumentList.Arguments.ElementAt(0).Expression, ((MemberAccessExpressionSyntax)invocationExpressionNodeExpression).OperatorToken, ((MemberAccessExpressionSyntax)invocationExpressionNodeExpression).Name);
}
else if (node.Expression.CSharpKind() == SyntaxKind.IdentifierName)
{
newMemberAccess = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, argumentList.Arguments.ElementAt(0).Expression, (IdentifierNameSyntax)invocationExpressionNodeExpression.WithLeadingTrivia());
}
else if (node.Expression.CSharpKind() == SyntaxKind.GenericName)
{
newMemberAccess = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, argumentList.Arguments.ElementAt(0).Expression, (GenericNameSyntax)invocationExpressionNodeExpression.WithLeadingTrivia());
}
else
{
Debug.Assert(false, "The expression kind is not MemberAccessExpression or IdentifierName or GenericName to be converted to Member Access Expression for Ext Method Reduction");
}
if (newMemberAccess == null)
{
return node;
}
// Preserve Trivia
newMemberAccess = newMemberAccess.WithLeadingTrivia(node.GetLeadingTrivia());
// Below removes the first argument
// we need to reuse the separators to maintain existing formatting & comments in the arguments itself
var newArguments = SyntaxFactory.SeparatedList<ArgumentSyntax>(argumentList.Arguments.GetWithSeparators().AsEnumerable().Skip(2));
var rewrittenArgumentList = argumentList.WithArguments(newArguments);
var candidateRewrittenNode = SyntaxFactory.InvocationExpression(newMemberAccess, rewrittenArgumentList);
var oldSymbol = semanticModel.GetSymbolInfo(node).Symbol;
var newSymbol = semanticModel.GetSpeculativeSymbolInfo(
node.SpanStart,
candidateRewrittenNode,
SpeculativeBindingOption.BindAsExpression).Symbol;
if (oldSymbol != null && newSymbol != null)
{
if (newSymbol.Kind == SymbolKind.Method && oldSymbol.Equals(((IMethodSymbol)newSymbol).GetConstructedReducedFrom()))
{
rewrittenNode = candidateRewrittenNode;
}
}
}
}
}
return rewrittenNode;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:68,代码来源:CSharpExtensionMethodReducer.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.SimpleNameSyntax类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论