Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy / Generators / Emitters / SimpleAST / MethodInvocationExpression.cs
blob9b458a2afb65711935eb62db5795c27646e68875
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.DynamicProxy.Generators.Emitters.SimpleAST
17 using System;
18 using System.Reflection;
19 using System.Reflection.Emit;
21 public class MethodInvocationExpression : Expression
23 protected readonly MethodInfo method;
24 protected readonly Expression[] args;
25 protected readonly Reference owner;
26 private bool virtualCall;
28 public MethodInvocationExpression(MethodInfo method, params Expression[] args) :
29 this(SelfReference.Self, method, args)
33 public MethodInvocationExpression(MethodEmitter method, params Expression[] args) :
34 this(SelfReference.Self, method.MethodBuilder, args)
38 public MethodInvocationExpression(Reference owner, MethodEmitter method, params Expression[] args) :
39 this(owner, method.MethodBuilder, args)
43 public MethodInvocationExpression(Reference owner, MethodInfo method, params Expression[] args)
45 this.owner = owner;
46 this.method = method;
47 this.args = args;
50 public bool VirtualCall
52 get { return virtualCall; }
53 set { virtualCall = value; }
56 public override void Emit(IMemberEmitter member, ILGenerator gen)
58 ArgumentsUtil.EmitLoadOwnerAndReference(owner, gen);
60 foreach(Expression exp in args)
62 exp.Emit(member, gen);
65 if (virtualCall)
67 gen.Emit(OpCodes.Callvirt, method);
69 else
71 gen.Emit(OpCodes.Call, method);