Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / DynamicProxy / Castle.DynamicProxy / Invocation / AbstractInvocation.cs
blob02709f31499cd3afb5a40dd1225b31bcd36573c1
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.Invocation
17 using System;
18 using System.Reflection;
20 public abstract class AbstractInvocation : MarshalByRefObject, IInvocation
22 protected ICallable callable;
23 private MethodInfo method;
24 private object proxy;
25 private object target;
26 protected object changed_target;
28 public AbstractInvocation( ICallable callable, object proxy, MethodInfo method, object newtarget )
30 this.callable = callable;
31 this.proxy = proxy;
33 this.target = callable.Target;
35 if (newtarget != null)
37 this.target = newtarget;
40 this.method = method;
43 public object Proxy
45 get { return proxy; }
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 );
72 else
74 return Method.Invoke( changed_target, args );