本文整理汇总了C#中InvocationExpressionSyntax类的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpressionSyntax类的具体用法?C# InvocationExpressionSyntax怎么用?C# InvocationExpressionSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvocationExpressionSyntax类属于命名空间,在下文中一共展示了InvocationExpressionSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;
if (symbol != null)
{
Enums.AsyncDetected type = DetectCPUAsynchronousUsages(node,symbol);
Result.StoreDetectedCPUAsyncUsage(type);
// Check whether there are some blocking operations under task, threadpool, and thread!
//if (type == Enums.AsyncDetected.Task || type == Enums.AsyncDetected.Threadpool || type == Enums.AsyncDetected.Thread)
//{
// foreach (var methodCall in node.DescendantNodes().OfType<InvocationExpressionSyntax>())
// {
// var methodCallSymbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(methodCall).Symbol;
// if (methodCallSymbol != null)
// {
// var synctype = ((IMethodSymbol)methodCallSymbol.OriginalDefinition).DetectSynchronousUsages(SemanticModel);
// if (synctype != Utilities.Enums.SyncDetected.None)
// Logs.TempLog.Info("LONGRUNNING {0} {1}{2}--------------------------", methodCallSymbol, Document.FilePath, node.ToLog());
// }
// }
//}
}
base.VisitInvocationExpression(node);
}
示例2: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;
if (symbol != null)
{
var type = DetectIOAsynchronousUsages(node, symbol);
Result.StoreDetectedIOAsyncUsage(type);
//DetectBlockingOperations(node, symbol);
//if (type == Enums.AsyncDetected.EAP)
// Logs.TempLog2.Info("{0}{1}*****************************************", Document.FilePath, node.FirstAncestorOrSelf<MethodDeclarationSyntax>().ToLog());
if (type == Enums.AsyncDetected.TAP)
//Logs.TempLog3.Info("{0}{1}*****************************************", Document.FilePath, node.FirstAncestorOrSelf<MethodDeclarationSyntax>().ToLog());
Logs.TempLog3.Info("{0}", symbol);
//if (type == Enums.AsyncDetected.APM)
// Logs.TempLog4.Info("{0}{1}*****************************************", Document.FilePath, node.FirstAncestorOrSelf<MethodDeclarationSyntax>().ToLog());
}
base.VisitInvocationExpression(node);
}
示例3: FindAsyncStateInvocationArgument
public static ArgumentSyntax FindAsyncStateInvocationArgument(InvocationExpressionSyntax apmSyntax, IMethodSymbol apmSymbol)
{
var parameterIndex = FindMethodParameterIndex(apmSymbol, "object", "state");
var callbackArgument = apmSyntax.ArgumentList.Arguments.ElementAt(parameterIndex);
return callbackArgument;
}
示例4: MakeUppercaseAsync
async Task<Document> MakeUppercaseAsync(Document document, InvocationExpressionSyntax invocation,
CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var typeSymbol = semanticModel.GetSymbolInfo(invocation.Expression, cancellationToken).Symbol;
var nfluentCheck = semanticModel.Compilation.NFluentCheckType();
if (typeSymbol == null || nfluentCheck == null) return document;
var newMethod = typeSymbol.Name == "AreEqual" ? "IsEqualTo" : "IsNotEqualTo";
var checkThat = CheckThat(nfluentCheck, invocation.ArgumentList.Arguments[1]);
var replacement = InvocationExpression(
MemberAccessExpression(
SyntaxKind.SimpleMemberAccessExpression,
checkThat,
IdentifierName(newMethod)),
ArgumentList(SingletonSeparatedList(invocation.ArgumentList.Arguments[0])))
.WithTriviaFrom(invocation);
var syntaxRoot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var newSyntaxRoot = syntaxRoot.ReplaceNode(invocation, replacement);
var newDocument = document.WithSyntaxRoot(newSyntaxRoot);
var withUsings = await UsingHelpers.AddUsingsAsync(newDocument, replacement, cancellationToken,
nfluentCheck.ContainingNamespace);
return withUsings;
}
示例5: GetDelegateInvokeItems
private IEnumerable<SignatureHelpItem> GetDelegateInvokeItems(
InvocationExpressionSyntax invocationExpression, SemanticModel semanticModel, ISymbolDisplayService symbolDisplayService, IAnonymousTypeDisplayService anonymousTypeDisplayService,
IDocumentationCommentFormattingService documentationCommentFormattingService, ISymbol within, INamedTypeSymbol delegateType, CancellationToken cancellationToken)
{
var invokeMethod = delegateType.DelegateInvokeMethod;
if (invokeMethod == null)
{
return null;
}
// Events can only be invoked directly from the class they were declared in.
var expressionSymbol = semanticModel.GetSymbolInfo(invocationExpression.Expression, cancellationToken).GetAnySymbol();
if (expressionSymbol.IsKind(SymbolKind.Event) &&
!expressionSymbol.ContainingType.OriginalDefinition.Equals(within.OriginalDefinition))
{
return null;
}
var position = invocationExpression.SpanStart;
var item = CreateItem(
invokeMethod, semanticModel, position,
symbolDisplayService, anonymousTypeDisplayService,
isVariadic: invokeMethod.IsParams(),
documentation: SpecializedCollections.EmptyEnumerable<SymbolDisplayPart>(),
prefixParts: GetDelegateInvokePreambleParts(invokeMethod, semanticModel, position),
separatorParts: GetSeparatorParts(),
suffixParts: GetDelegateInvokePostambleParts(),
parameters: GetDelegateInvokeParameters(invokeMethod, semanticModel, position, documentationCommentFormattingService, cancellationToken));
return SpecializedCollections.SingletonEnumerable(item);
}
示例6: ConvertToInterpolatedString
private Task<Document> ConvertToInterpolatedString(Document document, SyntaxNode root, InvocationExpressionSyntax invocation, CancellationToken cancellationToken)
{
string previousString = null;
var parts = new List<InterpolatedStringContentSyntax>(invocation.ArgumentList.Arguments.Count);
for (int i = 0; i < invocation.ArgumentList.Arguments.Count; i++)
{
ArgumentSyntax argument = invocation.ArgumentList.Arguments[i];
var literal = argument.Expression as LiteralExpressionSyntax;
if (literal?.IsKind(SyntaxKind.StringLiteralExpression) ?? false)
{
//strings needs to be collapsed, otherwise VS will insert additional whitespaces
previousString += literal.Token.Text.Substring(1, literal.Token.Text.Length - 2);
}
else
{
if (previousString != null)
{
parts.Add(InterpolatedStringGenerator.TextPart(previousString));
previousString = null;
}
parts.Add(InterpolatedStringGenerator.ExpressionPart(argument.Expression.WithoutLeadingTrivia().WithoutTrailingTrivia()));
}
}
if (previousString != null)
{
parts.Add(InterpolatedStringGenerator.TextPart(previousString));
}
SyntaxNode interpolated = InterpolatedStringGenerator.InterpolatedString(parts);
root = root.ReplaceNode(invocation, interpolated);
return Task.FromResult(document.WithSyntaxRoot(root));
}
示例7: VisitInvocationExpression
public override SyntaxNode VisitInvocationExpression(InvocationExpressionSyntax node)
{
// Replace the module method name with a qualified one if this is a module ctor
bool nodeChanged = IsInvocationAModuleCtor(node);
ExpressionSyntax nodeExpression = nodeChanged
? ((IdentifierNameSyntax)node.Expression).WithIdentifier(
SyntaxFactory.Identifier("ConfigScript." + ((IdentifierNameSyntax)node.Expression).Identifier.Text)
.WithTriviaFrom(((IdentifierNameSyntax)node.Expression).Identifier))
: node.Expression;
// Get a hash of all the previous @doc and @ctx lambda parameters and don't replace the same
HashSet<string> currentScopeLambdaParameters = new HashSet<string>(
node.Ancestors().OfType<LambdaExpressionSyntax>().SelectMany(
x => x.DescendantNodes().OfType<ParameterSyntax>()).Select(x => x.Identifier.Text));
// Only do the replacement if this is a module ctor or a module fluent method
ArgumentListSyntax argumentList = node.ArgumentList;
if(nodeChanged || IsInvocationAFluentMethod(node))
{
// Replace @doc and @ctx argument expressions with the appropriate lambda expressions, and stop descending if we hit another module ctor
foreach (ArgumentSyntax argument in node.ArgumentList.Arguments)
{
// Don't replace existing lambda expressions
if (!(argument.Expression is LambdaExpressionSyntax))
{
List<IdentifierNameSyntax> identifierNames = argument
.DescendantNodes(x => !(x is InvocationExpressionSyntax) || !IsInvocationAModuleCtorOrFluentMethod((InvocationExpressionSyntax)x))
.OfType<IdentifierNameSyntax>()
.Where(x => x != null && !currentScopeLambdaParameters.Contains(x.Identifier.Text))
.ToList();
IdentifierNameSyntax docReplacementName = identifierNames.FirstOrDefault(x => x.Identifier.Text.StartsWith("@doc"));
IdentifierNameSyntax ctxReplacementName = identifierNames.FirstOrDefault(x => x.Identifier.Text.StartsWith("@ctx"));
if (docReplacementName != null)
{
argumentList = argumentList.ReplaceNode(argument, SyntaxFactory.Argument(
SyntaxFactory.ParenthesizedLambdaExpression(
SyntaxFactory.ParameterList(
new SeparatedSyntaxList<ParameterSyntax>()
.Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(docReplacementName.Identifier.Text)))
.Add(SyntaxFactory.Parameter(SyntaxFactory.Identifier(ctxReplacementName == null ? "_" : ctxReplacementName.Identifier.Text)))),
argument.Expression))
.WithTriviaFrom(argument));
nodeChanged = true;
}
else if (ctxReplacementName != null)
{
argumentList = argumentList.ReplaceNode(argument, SyntaxFactory.Argument(
SyntaxFactory.SimpleLambdaExpression(
SyntaxFactory.Parameter(SyntaxFactory.Identifier(ctxReplacementName.Identifier.Text)),
argument.Expression))
.WithTriviaFrom(argument));
nodeChanged = true;
}
}
}
}
// Build and return the result node (or just return the original node)
return base.VisitInvocationExpression(nodeChanged ? node.WithExpression(nodeExpression).WithArgumentList(argumentList) : node);
}
示例8: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpressionSyntax node)
{
var symbol = (IMethodSymbol)SemanticModel.GetSymbolInfo(node).Symbol;
if (symbol != null)
{
if(symbol.ToString().Contains("System.Threading.Tasks.Task.WaitAll"))
{
var block = node.Ancestors().OfType<BlockSyntax>().First();
if (block.DescendantNodes().OfType<ForEachStatementSyntax>().Any() || block.DescendantNodes().OfType<ForStatementSyntax>().Any())
return;
foreach (var invocation in block.DescendantNodes().OfType<InvocationExpressionSyntax>())
{
var symbol2 = (IMethodSymbol)SemanticModel.GetSymbolInfo(invocation).Symbol;
if (symbol2!=null && symbol2.IsTaskCreationMethod())
{
Logs.TempLog3.Info("{0}{1}--------------------------", Document.FilePath, block.ToLog());
break;
}
}
}
}
base.VisitInvocationExpression(node);
}
示例9: CheckIsInstanceOfTypeCallWithTypeArgument
private static void CheckIsInstanceOfTypeCallWithTypeArgument(InvocationExpressionSyntax invocation, IMethodSymbol methodSymbol,
SyntaxNodeAnalysisContext context)
{
if (methodSymbol.Name != "IsInstanceOfType" ||
!methodSymbol.ContainingType.Is(KnownType.System_Type) ||
!invocation.HasExactlyNArguments(1))
{
return;
}
var argument = invocation.ArgumentList.Arguments.First().Expression;
var typeInfo = context.SemanticModel.GetTypeInfo(argument).Type;
if (!typeInfo.Is(KnownType.System_Type))
{
return;
}
var invocationInArgument = argument as InvocationExpressionSyntax;
var message = IsGetTypeCall(invocationInArgument, context.SemanticModel)
? MessageIsInstanceOfTypeWithGetType
: MessageIsInstanceOfType;
context.ReportDiagnostic(Diagnostic.Create(Rule, argument.GetLocation(), message));
}
示例10: CreateInterpolatedString
private async Task<Document> CreateInterpolatedString(InvocationExpressionSyntax invocation, Document document, CancellationToken cancellationToken)
{
Assert(invocation.ArgumentList != null);
Assert(invocation.ArgumentList.Arguments.Count >= 2);
Assert(invocation.ArgumentList.Arguments[0].Expression.IsKind(SyntaxKind.StringLiteralExpression));
var semanticModel = await document.GetSemanticModelAsync(cancellationToken);
var arguments = invocation.ArgumentList.Arguments;
var text = ((LiteralExpressionSyntax)arguments[0].Expression).Token.ToString();
var builder = ImmutableArray.CreateBuilder<ExpressionSyntax>();
for (int i = 1; i < arguments.Count; i++)
{
builder.Add(CastAndParenthesize(arguments[i].Expression, semanticModel));
}
var expandedArguments = builder.ToImmutable();
var interpolatedString = (InterpolatedStringExpressionSyntax)SyntaxFactory.ParseExpression("$" + text);
var newInterpolatedString = InterpolatedStringRewriter.Visit(interpolatedString, expandedArguments);
var root = await document.GetSyntaxRootAsync(cancellationToken);
var newRoot = root.ReplaceNode(invocation, newInterpolatedString);
return document.WithSyntaxRoot(newRoot);
}
示例11: PerformAction
static Document PerformAction(Document document, SyntaxNode root, InvocationExpressionSyntax invocationNode)
{
var arg = invocationNode.ArgumentList.Arguments.Select(a => a.Expression).First();
if (!arg.DescendantNodesAndSelf().OfType<BinaryExpressionSyntax>().All(bop => bop.IsKind(SyntaxKind.BitwiseOrExpression)))
return document;
arg = ConvertBitwiseFlagComparisonToHasFlagsCodeRefactoringProvider.MakeFlatExpression(arg, SyntaxKind.BitwiseAndExpression);
if (arg is BinaryExpressionSyntax)
arg = SyntaxFactory.ParenthesizedExpression(arg);
SyntaxNode nodeToReplace = invocationNode;
while (nodeToReplace.Parent is ParenthesizedExpressionSyntax)
nodeToReplace = nodeToReplace.Parent;
bool negateHasFlags = nodeToReplace.Parent != null && nodeToReplace.Parent.IsKind(SyntaxKind.LogicalNotExpression);
if (negateHasFlags)
nodeToReplace = nodeToReplace.Parent;
var expr = SyntaxFactory.BinaryExpression(
negateHasFlags ? SyntaxKind.EqualsExpression : SyntaxKind.NotEqualsExpression,
SyntaxFactory.ParenthesizedExpression(SyntaxFactory.BinaryExpression(SyntaxKind.BitwiseAndExpression, ((MemberAccessExpressionSyntax)invocationNode.Expression).Expression, arg))
.WithAdditionalAnnotations(Formatter.Annotation),
SyntaxFactory.ParseExpression("0")
);
var newRoot = root.ReplaceNode((SyntaxNode)
nodeToReplace,
expr.WithAdditionalAnnotations(Formatter.Annotation)
);
return document.WithSyntaxRoot(newRoot);
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:31,代码来源:ConvertHasFlagsToBitwiseFlagComparisonCodeRefactoringProvider.cs
示例12: CreateRelacementNode
/// <summary>
/// Creates a new ExpressionSyntax to replace the defaultIfNull InvocationExpressionSyntax
/// </summary>
public static ExpressionSyntax CreateRelacementNode(InvocationExpressionSyntax defaultIfNullexpression)
{
// We should change from x.DefaultIfNull(y => y.z...) or x.DefaultIfNull(y => y.[..]...)
// into x?.z... x?[..]...
// Get the expression on which DefaultIfNull is invoked, this is the x
var rootExpression = (defaultIfNullexpression.Expression as MemberAccessExpressionSyntax)?.Expression;
// Get the first parameter to DefaultIfNull, this is the Lambda y => y.z...
var lambda = GetLambdaFromFirstArgument(defaultIfNullexpression);
if (lambda == null) return defaultIfNullexpression;
// Get the MemberAccessExpression y.z or ElementAccessExpression y[..] from the lamba body
var accessExpression = GetLeftMostAccessExpression(lambda);
if (accessExpression == null) return defaultIfNullexpression;
// A ConditionalAccessExpression requires a ..BindingExpression instead of the ..AccessExpression
var bindingExpression = ToBindingExpression(accessExpression);
// Replace the AccessExpression from the Labmda body with the BindingExpression this will result in the .z... or [..]... part
var whenNotNullExpression = (ExpressionSyntax)lambda.Body.ReplaceNode(accessExpression, bindingExpression)
.WithTriviaFrom(accessExpression);
// Combine the x and .z... into x?.z...
return SyntaxFactory.ConditionalAccessExpression(
expression: rootExpression,
whenNotNull: whenNotNullExpression).WithTriviaFrom(defaultIfNullexpression);
}
示例13: RewriteStatement
/// <summary>
/// Rewrites the statement with a monitor statement.
/// </summary>
/// <param name="node">LocalDeclarationStatementSyntax</param>
/// <returns>StatementSyntax</returns>
private SyntaxNode RewriteStatement(InvocationExpressionSyntax node)
{
var arguments = new List<ArgumentSyntax>();
arguments.Add(node.ArgumentList.Arguments[0]);
string payload = "";
for (int i = 1; i < node.ArgumentList.Arguments.Count; i++)
{
if (i == node.ArgumentList.Arguments.Count - 1)
{
payload += node.ArgumentList.Arguments[i].ToString();
}
else
{
payload += node.ArgumentList.Arguments[i].ToString() + ", ";
}
}
arguments[0] = SyntaxFactory.Argument(SyntaxFactory.ParseExpression(
"new " + arguments[0].ToString() + "(" + payload + ")"));
var rewritten = node.
WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList(arguments))).
WithExpression((node.Expression as GenericNameSyntax).
WithIdentifier(SyntaxFactory.Identifier("this.Monitor"))).
WithTriviaFrom(node);
return rewritten;
}
示例14: RemoveCall
private static SyntaxNode RemoveCall(SyntaxNode root,
InvocationExpressionSyntax castInvocation, MemberAccessExpressionSyntax memberAccess)
{
return castInvocation != null
? RemoveExtensionMethodCall(root, castInvocation)
: RemoveStaticMemberCall(root, memberAccess);
}
示例15: HasCheckForNullThatReturns
private static bool HasCheckForNullThatReturns(InvocationExpressionSyntax invocation, SemanticModel semanticModel, ISymbol symbol)
{
var method = invocation.FirstAncestorOfKind(SyntaxKind.MethodDeclaration) as MethodDeclarationSyntax;
if (method != null && method.Body != null)
{
var ifs = method.Body.Statements.OfKind(SyntaxKind.IfStatement);
foreach (IfStatementSyntax @if in ifs)
{
if ([email protected]?.IsKind(SyntaxKind.EqualsExpression) ?? true) continue;
var equals = (BinaryExpressionSyntax)@if.Condition;
if (equals.Left == null || equals.Right == null) continue;
if (@if.GetLocation().SourceSpan.Start > invocation.GetLocation().SourceSpan.Start) return false;
ISymbol identifierSymbol;
if (equals.Right.IsKind(SyntaxKind.NullLiteralExpression) && equals.Left.IsKind(SyntaxKind.IdentifierName))
identifierSymbol = semanticModel.GetSymbolInfo(equals.Left).Symbol;
else if (equals.Left.IsKind(SyntaxKind.NullLiteralExpression) && equals.Right.IsKind(SyntaxKind.IdentifierName))
identifierSymbol = semanticModel.GetSymbolInfo(equals.Right).Symbol;
else continue;
if (!symbol.Equals(identifierSymbol)) continue;
if (@if.Statement == null) continue;
if (@if.Statement.IsKind(SyntaxKind.Block))
{
var ifBlock = (BlockSyntax)@if.Statement;
if (ifBlock.Statements.OfKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement).Any()) return true;
}
else
{
if (@if.Statement.IsAnyKind(SyntaxKind.ThrowStatement, SyntaxKind.ReturnStatement)) return true;
}
}
}
return false;
}