main
 1using System.Collections.Generic;
 2using System.Reflection;
 3using System.Runtime.Remoting.Messaging;
 4using gorilla.commons.utility;
 5
 6namespace Gorilla.Commons.Infrastructure.Proxies
 7{
 8    public class MethodCallInvocation<T> : Invocation
 9    {
10        readonly IMethodCallMessage call;
11        readonly T target;
12        readonly Stack<Interceptor> interceptors;
13
14        public MethodCallInvocation(IEnumerable<Interceptor> interceptors, IMethodCallMessage call, T target)
15        {
16            this.call = call;
17            this.target = target;
18            this.interceptors = new Stack<Interceptor>(interceptors);
19            arguments = call.Properties["__Args"].downcast_to<object[]>();
20            method = call.MethodBase.downcast_to<MethodInfo>();
21        }
22
23        public object[] arguments { get; set; }
24
25        public MethodInfo method { get; set; }
26
27        public object return_value { get; set; }
28
29        public void proceed()
30        {
31            if (interceptors.Count > 0)
32            {
33                interceptors.Pop().intercept(this);
34                return;
35            }
36
37            try
38            {
39                return_value = call.MethodBase.Invoke(target, arguments);
40            }
41            catch (TargetInvocationException e)
42            {
43                throw e.InnerException.preserve_stack_trace();
44            }
45        }
46    }
47}