本文整理汇总了C#中InvocationExpression类的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpression类的具体用法?C# InvocationExpression怎么用?C# InvocationExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvocationExpression类属于命名空间,在下文中一共展示了InvocationExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpression anyInvoke)
{
base.VisitInvocationExpression (anyInvoke);
var match = pattern.Match (anyInvoke);
if (!match.Success)
return;
var anyResolve = ctx.Resolve (anyInvoke) as InvocationResolveResult;
if (anyResolve == null || anyResolve.Member.FullName != "System.Linq.Enumerable.Any")
return;
var whereInvoke = match.Get<InvocationExpression> ("whereInvoke").Single ();
var whereResolve = ctx.Resolve (whereInvoke) as InvocationResolveResult;
if (whereResolve == null || whereResolve.Member.FullName != "System.Linq.Enumerable.Where")
return;
if (whereResolve.Member.Parameters.Count != 2)
return;
var predResolve = whereResolve.Member.Parameters [1];
if (predResolve.Type.TypeParameterCount != 2)
return;
AddIssue (anyInvoke, "Redundant Where() call with predicate followed by Any()", script => {
var arg = whereInvoke.Arguments.Single ().Clone ();
var target = match.Get<Expression> ("target").Single ().Clone ();
script.Replace (anyInvoke, new InvocationExpression (new MemberReferenceExpression (target, "Any"), arg));
});
}
示例2: GetAllValidTypesFromInvocation
static IEnumerable<IType> GetAllValidTypesFromInvocation(CSharpAstResolver resolver, InvocationExpression invoke, AstNode parameter)
{
int index = GetArgumentIndex(invoke.Arguments, parameter);
if (index < 0)
yield break;
var targetResult = resolver.Resolve(invoke.Target) as MethodGroupResolveResult;
if (targetResult != null) {
foreach (var method in targetResult.Methods) {
if (index < method.Parameters.Count) {
if (method.Parameters [index].IsParams) {
var arrayType = method.Parameters [index].Type as ArrayType;
if (arrayType != null)
yield return arrayType.ElementType;
}
yield return method.Parameters [index].Type;
}
}
foreach (var extMethods in targetResult.GetExtensionMethods ()) {
foreach (var extMethod in extMethods) {
if (index + 1 < extMethod.Parameters.Count) {
if (extMethod.Parameters [index + 1].IsParams) {
var arrayType = extMethod.Parameters [index + 1].Type as ArrayType;
if (arrayType != null)
yield return arrayType.ElementType;
}
yield return extMethod.Parameters [index + 1].Type;
}
}
}
}
}
示例3: IsConditionallyRemoved
public static bool IsConditionallyRemoved(InvocationExpression invocationExpression, IEntity entity)
{
if (entity == null)
{
return false;
}
var result = new List<string>();
foreach (var a in entity.Attributes)
{
var type = a.AttributeType.GetDefinition();
if (type != null && type.FullName.Equals("System.Diagnostics.ConditionalAttribute", StringComparison.Ordinal))
{
if (a.PositionalArguments.Count > 0)
{
var symbol = a.PositionalArguments[0].ConstantValue as string;
if (symbol != null)
{
result.Add(symbol);
}
}
}
}
if (result.Count > 0)
{
var syntaxTree = invocationExpression.GetParent<SyntaxTree>();
if (syntaxTree != null)
{
return !result.Intersect(syntaxTree.ConditionalSymbols).Any();
}
}
return false;
}
示例4: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpression invocationExpression)
{
base.VisitInvocationExpression(invocationExpression);
// Speed up the inspector by discarding some invocations early
var hasEligibleArgument = invocationExpression.Arguments.Any(argument => {
var primitiveArg = argument as PrimitiveExpression;
return primitiveArg != null && primitiveArg.Value is string;
});
if (!hasEligibleArgument)
return;
var invocationResolveResult = context.Resolve(invocationExpression) as CSharpInvocationResolveResult;
if (invocationResolveResult == null)
return;
Expression formatArgument;
IList<Expression> formatArguments;
TextLocation formatStart;
if (!FormatStringHelper.TryGetFormattingParameters(invocationResolveResult, invocationExpression,
out formatArgument, out formatStart, out formatArguments, null)) {
return;
}
var primitiveArgument = formatArgument as PrimitiveExpression;
if (primitiveArgument == null || !(primitiveArgument.Value is string))
return;
var format = (string)primitiveArgument.Value;
var parsingResult = context.ParseFormatString(format);
CheckSegments(parsingResult.Segments, formatStart, formatArguments, invocationExpression);
}
示例5: GetActions
public IEnumerable<CodeAction> GetActions(RefactoringContext context)
{
if (!context.IsSomethingSelected) {
yield break;
}
var pexpr = context.GetNode<PrimitiveExpression>();
if (pexpr == null || !(pexpr.Value is string)) {
yield break;
}
if (pexpr.LiteralValue.StartsWith("@", StringComparison.Ordinal)) {
if (!(pexpr.StartLocation < new TextLocation(context.Location.Line, context.Location.Column - 1) && new TextLocation(context.Location.Line, context.Location.Column + 1) < pexpr.EndLocation)) {
yield break;
}
} else {
if (!(pexpr.StartLocation < context.Location && context.Location < pexpr.EndLocation)) {
yield break;
}
}
yield return new CodeAction (context.TranslateString("Introduce format item"), script => {
var invocation = context.GetNode<InvocationExpression>();
if (invocation != null && invocation.Target.IsMatch(PrototypeFormatReference)) {
AddFormatCallToInvocation(context, script, pexpr, invocation);
return;
}
var arg = CreateFormatArgument(context);
var newInvocation = new InvocationExpression (PrototypeFormatReference.Clone()) {
Arguments = { CreateFormatString(context, pexpr, 0), arg }
};
script.Replace(pexpr, newInvocation);
script.Select(arg);
});
}
示例6: VisitInvocationExpression
public override void VisitInvocationExpression (InvocationExpression anyInvoke)
{
base.VisitInvocationExpression (anyInvoke);
var match = pattern.Match (anyInvoke);
if (!match.Success)
return;
var anyResolve = ctx.Resolve (anyInvoke) as InvocationResolveResult;
if (anyResolve == null || !HasPredicateVersion(anyResolve.Member))
return;
var whereInvoke = match.Get<InvocationExpression> ("whereInvoke").Single ();
var whereResolve = ctx.Resolve (whereInvoke) as InvocationResolveResult;
if (whereResolve == null || whereResolve.Member.Name != "Where" || !IsQueryExtensionClass(whereResolve.Member.DeclaringTypeDefinition))
return;
if (whereResolve.Member.Parameters.Count != 2)
return;
var predResolve = whereResolve.Member.Parameters [1];
if (predResolve.Type.TypeParameterCount != 2)
return;
AddIssue (
anyInvoke, string.Format("Redundant Where() call with predicate followed by {0}()", anyResolve.Member.Name),
script => {
var arg = whereInvoke.Arguments.Single ().Clone ();
var target = match.Get<Expression> ("target").Single ().Clone ();
script.Replace (anyInvoke, new InvocationExpression (new MemberReferenceExpression (target, anyResolve.Member.Name), arg));
});
}
示例7: AssertInvokeIsOptimized
private static void AssertInvokeIsOptimized(InvocationExpression expr, Expression expression, IReadOnlyList<Expression> args)
{
var n = args.Count;
var updated = Update(expr);
var visited = Visit(expr);
foreach (var node in new[] { expr, updated, visited })
{
Assert.Same(expression, node.Expression);
AssertInvocation(n, node);
var argProvider = node as IArgumentProvider;
Assert.NotNull(argProvider);
Assert.Equal(n, argProvider.ArgumentCount);
if (node != visited) // our visitor clones argument nodes
{
for (var i = 0; i < n; i++)
{
Assert.Same(args[i], argProvider.GetArgument(i));
Assert.Same(args[i], node.Arguments[i]);
}
}
}
}
示例8: TryGetFormattingParameters
public static bool TryGetFormattingParameters(CSharpInvocationResolveResult invocationResolveResult, InvocationExpression invocationExpression,
out Expression formatArgument, out TextLocation formatStart, out IList<Expression> arguments,
Func<IParameter, Expression, bool> argumentFilter)
{
if (argumentFilter == null)
argumentFilter = (p, e) => true;
formatArgument = null;
formatStart = default(TextLocation);
arguments = new List<Expression>();
var argumentToParameterMap = invocationResolveResult.GetArgumentToParameterMap();
var resolvedParameters = invocationResolveResult.Member.Parameters;
var allArguments = invocationExpression.Arguments.ToArray();
for (int i = 0; i < allArguments.Length; i++) {
var parameterIndex = argumentToParameterMap[i];
if (parameterIndex < 0 || parameterIndex >= resolvedParameters.Count) {
// No valid mapping for this parameter, skip it
continue;
}
var parameter = resolvedParameters[parameterIndex];
var argument = allArguments[i];
if (parameter.Type.IsKnownType(KnownTypeCode.String) && parameterNames.Contains(parameter.Name)) {
formatArgument = argument;
formatStart = argument.StartLocation;
} else if ((formatArgument != null || parameter.IsParams) && argumentFilter(parameter, argument)) {
arguments.Add(argument);
}
}
return formatArgument != null;
}
示例9: GetResolved
private void GetResolved(InvocationExpression invocationExpression, Action<CSharpInvocationResolveResult> resolved)
{
if (_Resolver.resolveResults.ContainsKey(invocationExpression))
{
var result = _Resolver.resolveResults[invocationExpression] as CSharpInvocationResolveResult;
if (result != null) resolved(result);
}
}
示例10: ExpressionListBlock
public ExpressionListBlock(IEmitter emitter, IEnumerable<Expression> expressions, Expression paramArg, InvocationExpression invocation = null)
: base(emitter, null)
{
this.Emitter = emitter;
this.Expressions = expressions;
this.ParamExpression = paramArg;
this.InvocationExpression = invocation;
}
示例11: CouldBeExpressionTree
public static bool CouldBeExpressionTree(InvocationExpression expr)
{
if (expr != null && expr.Arguments.Count == 2) {
IMethod mr = expr.Annotation<IMethod>();
return mr != null && mr.Name == "Lambda" && mr.DeclaringType.FullName == "System.Linq.Expressions.Expression";
}
return false;
}
示例12: UpdateInvocation
protected InvocationExpression UpdateInvocation(InvocationExpression iv, Expression expression, IEnumerable<Expression> args)
{
if (args != iv.Arguments || expression != iv.Expression)
{
return Expression.Invoke(expression, args);
}
return iv;
}
示例13: ToStaticMethodInvocation
AstNode ToStaticMethodInvocation(InvocationExpression invocation, MemberReferenceExpression memberReference,
CSharpInvocationResolveResult invocationRR)
{
var newArgumentList = invocation.Arguments.Select(arg => arg.Clone()).ToList();
newArgumentList.Insert(0, memberReference.Target.Clone());
var newTarget = memberReference.Clone() as MemberReferenceExpression;
newTarget.Target = new IdentifierExpression(invocationRR.Member.DeclaringType.Name);
return new InvocationExpression(newTarget, newArgumentList);
}
示例14: AddFormatCallToInvocation
void AddFormatCallToInvocation (RefactoringContext context, Script script, PrimitiveExpression pExpr, InvocationExpression invocation)
{
var newInvocation = (InvocationExpression)invocation.Clone ();
newInvocation.Arguments.First ().ReplaceWith (CreateFormatString (context, pExpr, newInvocation.Arguments.Count () - 1));
newInvocation.Arguments.Add (CreateFormatArgument (context));
script.Replace (invocation, newInvocation);
}
示例15: VerifyArgumentUsage
protected override bool VerifyArgumentUsage(InvocationExpression invocationExpression)
{
var firstParam = invocationExpression.Arguments.First() as PrimitiveExpression;
if(firstParam != null)
{
return firstParam.Value.ToString().ToLower() == "hello world";
}
return false;
}