1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
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
)
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
);
67 gen
.Emit(OpCodes
.Callvirt
, method
);
71 gen
.Emit(OpCodes
.Call
, method
);