本文整理汇总了C#中ICSharpCode.NRefactory.Ast.InvocationExpression类的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpression类的具体用法?C# InvocationExpression怎么用?C# InvocationExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvocationExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了InvocationExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitInvocationExpression
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
var memberReferenceExpression = invocationExpression.TargetObject as MemberReferenceExpression;
if (memberReferenceExpression == null)
return base.VisitInvocationExpression(invocationExpression, data);
LambdaExpression lambdaExpression;
switch (memberReferenceExpression.MemberName)
{
case "Select":
if (invocationExpression.Arguments.Count != 1)
return base.VisitInvocationExpression(invocationExpression, data);
lambdaExpression = invocationExpression.Arguments[0] as LambdaExpression;
break;
case "SelectMany":
if (invocationExpression.Arguments.Count != 2)
return base.VisitInvocationExpression(invocationExpression, data);
lambdaExpression = invocationExpression.Arguments[1] as LambdaExpression;
break;
default:
return base.VisitInvocationExpression(invocationExpression, data);
}
if (lambdaExpression == null)
return base.VisitInvocationExpression(invocationExpression, data);
ProcessQuery(lambdaExpression.ExpressionBody);
return base.VisitInvocationExpression(invocationExpression, data);
}
示例2: TrackedVisitInvocationExpression
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
if (invocationExpression.TargetObject is FieldReferenceExpression)
{
FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;
string methodName = targetObject.FieldName;
TypeDeclaration typeDeclaration = GetEnclosingTypeDeclaration(invocationExpression);
TypeDeclaration thisTypeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
if (typeDeclaration != null && IsTestFixture(thisTypeDeclaration))
{
IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
IList specialMethods = GetMethods(methods, methodName);
if (ContainsInternalMethod(specialMethods))
{
Expression replacedExpression;
MethodDeclaration method = (MethodDeclaration) specialMethods[0];
bool staticMethod = AstUtil.ContainsModifier(method, Modifiers.Static);
replacedExpression = CreateReflectionInvocation(invocationExpression, staticMethod);
if (invocationExpression.Parent is Expression || invocationExpression.Parent is VariableDeclaration)
{
TypeReference returnType = GetInternalMethodReturnType(specialMethods);
CastExpression castExpression = new CastExpression(returnType, replacedExpression, CastType.Cast);
replacedExpression = castExpression;
}
ReplaceCurrentNode(replacedExpression);
}
}
}
return base.TrackedVisitInvocationExpression(invocationExpression, data);
}
示例3: add_Invocation
//, AstExpression expression)
public static InvocationExpression add_Invocation(this BlockStatement blockStatement, string typeName, string methodName, params object[] parameters)
{
if (methodName.valid().isFalse())
return null;
Expression memberExpression = null;
if (typeName.valid())
memberExpression = new MemberReferenceExpression(new IdentifierExpression(typeName), methodName);
else
memberExpression = new IdentifierExpression(methodName);
var memberReference = new InvocationExpression(memberExpression);
if (parameters != null)
{
var arguments = new List<Expression>();
foreach (var parameter in parameters)
if (parameter is Expression)
arguments.add(parameter as Expression);
else
arguments.add(new PrimitiveExpression(parameter, parameter.str()));
memberReference.Arguments = arguments;
}
blockStatement.append(memberReference.expressionStatement());
return memberReference;
}
示例4: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference stringReference = new TypeReference("System.String");
MethodDeclaration method = new MethodDeclaration("ToString",
Modifiers.Public | Modifiers.Override,
stringReference,
null, null);
method.Body = new BlockStatement();
Expression target = new FieldReferenceExpression(new TypeReferenceExpression(stringReference),
"Format");
InvocationExpression methodCall = new InvocationExpression(target);
StringBuilder formatString = new StringBuilder();
formatString.Append('[');
formatString.Append(currentClass.Name);
for (int i = 0; i < items.Count; i++) {
formatString.Append(' ');
formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name));
formatString.Append("={");
formatString.Append(i);
formatString.Append('}');
}
formatString.Append(']');
methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
foreach (FieldWrapper w in items) {
methodCall.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
}
method.Body.AddChild(new ReturnStatement(methodCall));
nodes.Add(method);
}
示例5: TrackedVisitInvocationExpression
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
if (invocationExpression.TargetObject is FieldReferenceExpression)
{
FieldReferenceExpression targetObject = (FieldReferenceExpression) invocationExpression.TargetObject;
if (targetObject.FieldName == "toArray" || targetObject.FieldName == "ToArray")
{
Expression invoker = targetObject.TargetObject;
TypeReference invokerType = GetExpressionType(invoker);
if (invokerType != null && collectionTypes.Contains(invokerType.Type))
{
if (invocationExpression.Arguments.Count == 1)
{
Expression argExpression = (Expression) invocationExpression.Arguments[0];
if (argExpression is ArrayCreateExpression)
{
InvocationExpression newInvocation = invocationExpression;
TypeReference old = ((ArrayCreateExpression) argExpression).CreateType;
TypeReference tr = new TypeReference(old.Type);
TypeOfExpression tof = new TypeOfExpression(tr);
tr.Parent = tof;
tof.Parent = newInvocation;
newInvocation.Arguments.Clear();
newInvocation.Arguments.Add(tof);
ReplaceCurrentNode(newInvocation);
}
}
}
}
}
return base.TrackedVisitInvocationExpression(invocationExpression, data);
}
示例6: ModifyLambdaForSelectMany
private static INode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
ParenthesizedExpression parenthesizedlambdaExpression,
InvocationExpression invocationExpression)
{
INode node = lambdaExpression;
var argPos = invocationExpression.Arguments.IndexOf(lambdaExpression);
switch (argPos)
{
case 0: // first one, select the collection
// need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
var selectManyExpression = new LambdaExpression
{
ExpressionBody =
new CastExpression(new TypeReference("IEnumerable<dynamic>"),
new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
Parameters = lambdaExpression.Parameters,
};
node = new CastExpression(new TypeReference("Func<dynamic, IEnumerable<dynamic>>"),
new ParenthesizedExpression(selectManyExpression), CastType.Cast);
break;
case 1: // the transformation func
node = new CastExpression(new TypeReference("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression,
CastType.Cast);
break;
}
return node;
}
示例7: TrackedVisitInvocationExpression
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
Expression invocationTarget = invocationExpression.TargetObject;
if (invocationTarget is FieldReferenceExpression)
{
FieldReferenceExpression methodTargetObject = (FieldReferenceExpression) invocationTarget;
Expression invoker = methodTargetObject.TargetObject;
TypeReference invokerType = GetExpressionType(invoker);
if (invokerType != null)
{
ReplaceMember(invocationExpression, data, invokerType);
}
}
else if (invocationTarget is IdentifierExpression)
{
TypeDeclaration typeDeclaration = (TypeDeclaration) AstUtil.GetParentOfType(invocationExpression, typeof(TypeDeclaration));
VerifyDerivedMethod(typeDeclaration, invocationExpression, data);
}
if (invocationExpression.TypeArguments.Count == 0)
return base.TrackedVisitInvocationExpression(invocationExpression, data);
else
{
invocationExpression.TypeArguments.Clear();
return null;
}
}
示例8: TrackedVisitConstructorDeclaration
public override object TrackedVisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data)
{
const string initializerBlock = "InitializerBlock";
if (constructorDeclaration.Name == initializerBlock)
{
TypeDeclaration type = (TypeDeclaration) constructorDeclaration.Parent;
string initName = "Init" + type.Name;
MethodDeclaration initMethod = GetInitMethod(type);
initMethod.Body.Children.AddRange(constructorDeclaration.Body.Children);
Expression initInvocation = new InvocationExpression(new IdentifierExpression(initName));
ExpressionStatement initInvocationStatement = new ExpressionStatement(initInvocation);
IList constructors = AstUtil.GetChildrenWithType(type, typeof(ConstructorDeclaration));
if (constructors.Count > 1)
{
foreach (ConstructorDeclaration constructor in constructors)
{
if (constructor.Name != initializerBlock && !HasInitInvocation(constructor))
constructor.Body.Children.Insert(0, initInvocationStatement);
}
}
else if (((ConstructorDeclaration) constructors[0]).Name == initializerBlock)
{
ConstructorDeclaration constructor = new ConstructorDeclaration(type.Name, Modifiers.Public, null, null);
constructor.Body = new BlockStatement();
constructor.Body.AddChild(initInvocationStatement);
type.AddChild(constructor);
}
RemoveCurrentNode();
}
return base.TrackedVisitConstructorDeclaration(constructorDeclaration, data);
}
示例9: CheckGenericInvoke
void CheckGenericInvoke(InvocationExpression expr)
{
Assert.AreEqual(1, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
Assert.AreEqual("myMethod", ((IdentifierExpression)expr.TargetObject).Identifier);
Assert.AreEqual(1, expr.TypeArguments.Count);
Assert.AreEqual("System.Char", expr.TypeArguments[0].SystemType);
}
示例10: VisitInvocationExpression
public override object VisitInvocationExpression(InvocationExpression invocation, object data)
{
if (GetPrecedence(invocation.TargetObject) >= GetPrecedence(invocation)) {
invocation.TargetObject = Deparenthesize(invocation.TargetObject);
}
for(int i = 0; i < invocation.Arguments.Count; i++) {
invocation.Arguments[i] = Deparenthesize(invocation.Arguments[i]);
}
return base.VisitInvocationExpression(invocation, data);
}
示例11: TrackedVisitInvocationExpression
public override object TrackedVisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
if (invocationExpression.TargetObject is IdentifierExpression)
{
IdentifierExpression identifierExpression = (IdentifierExpression) invocationExpression.TargetObject;
if (Methods.Contains(identifierExpression.Identifier) && data is IList)
((IList) data).Add(invocationExpression);
}
return base.TrackedVisitInvocationExpression(invocationExpression, data);
}
示例12: IdentifierOnlyInvocation
public void IdentifierOnlyInvocation()
{
// InitializeComponents();
IdentifierExpression identifier = new IdentifierExpression("InitializeComponents");
InvocationExpression invocation = new InvocationExpression(identifier, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression);
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
Assert.AreEqual("InitializeComponents", mie.Method.MethodName);
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression);
}
示例13: MethodOnThisReferenceInvocation
public void MethodOnThisReferenceInvocation()
{
// InitializeComponents();
MemberReferenceExpression field = new MemberReferenceExpression(new ThisReferenceExpression(), "InitializeComponents");
InvocationExpression invocation = new InvocationExpression(field, new List<Expression>());
object output = invocation.AcceptVisitor(new CodeDomVisitor(), null);
Assert.IsTrue(output is CodeMethodInvokeExpression);
CodeMethodInvokeExpression mie = (CodeMethodInvokeExpression)output;
Assert.AreEqual("InitializeComponents", mie.Method.MethodName);
Assert.IsTrue(mie.Method.TargetObject is CodeThisReferenceExpression);
}
示例14: CheckGenericInvoke2
void CheckGenericInvoke2(InvocationExpression expr)
{
Assert.AreEqual(0, expr.Arguments.Count);
Assert.IsTrue(expr.TargetObject is IdentifierExpression);
IdentifierExpression ident = (IdentifierExpression)expr.TargetObject;
Assert.AreEqual("myMethod", ident.Identifier);
Assert.AreEqual(2, ident.TypeArguments.Count);
Assert.AreEqual("T", ident.TypeArguments[0].Type);
Assert.IsFalse(ident.TypeArguments[0].IsKeyword);
Assert.AreEqual("System.Boolean", ident.TypeArguments[1].Type);
Assert.IsTrue(ident.TypeArguments[1].IsKeyword);
}
示例15: CreateGetClassMethodInvocation
private InvocationExpression CreateGetClassMethodInvocation(TypeOfExpression typeOfExpression)
{
FieldReferenceExpression argument = new FieldReferenceExpression(typeOfExpression, "AssemblyQualifiedName");
typeOfExpression.Parent = argument;
List<Expression> arguments = new List<Expression>();
arguments.Add(argument);
IdentifierExpression methodIdentifier = new IdentifierExpression("java.lang.Class");
FieldReferenceExpression methodReference = new FieldReferenceExpression(methodIdentifier, "forName");
InvocationExpression invocationExpression = new InvocationExpression(methodReference, arguments);
argument.Parent = invocationExpression;
methodReference.Parent = invocationExpression;
return invocationExpression;
}