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
.Invocation
18 using System
.Reflection
;
20 public abstract class AbstractInvocation
: MarshalByRefObject
, IInvocation
22 protected ICallable callable
;
23 private MethodInfo method
;
25 private object target
;
26 protected object changed_target
;
28 public AbstractInvocation( ICallable callable
, object proxy
, MethodInfo method
, object newtarget
)
30 this.callable
= callable
;
33 this.target
= callable
.Target
;
35 if (newtarget
!= null)
37 this.target
= newtarget
;
48 public object InvocationTarget
50 get { return changed_target != null ? changed_target : target; }
51 set { changed_target = value; }
54 public MethodInfo Method
56 get { return method; }
59 public MethodInfo MethodInvocationTarget
61 get { return Method; }
64 public virtual object Proceed(params object[] args
)
66 // If the user changed the target, we use reflection
67 // otherwise the delegate will be used.
68 if (changed_target
== null)
70 return callable
.Call( args
);
74 return Method
.Invoke( changed_target
, args
);