main
 1using System.Collections.Generic;
 2using Castle.Core.Interceptor;
 3using gorilla.commons.utility;
 4
 5namespace gorilla.commons.infrastructure.thirdparty.Castle.DynamicProxy.Interceptors
 6{
 7    public class CastleDynamicMethodCallTracker<TypeToProxy> : MethodCallTracker<TypeToProxy>
 8    {
 9        readonly IList<string> the_name_of_each_method_to_intercept;
10
11        public CastleDynamicMethodCallTracker() : this(new List<string>())
12        {
13        }
14
15        public CastleDynamicMethodCallTracker(IList<string> the_name_of_each_method_to_intercept)
16        {
17            this.the_name_of_each_method_to_intercept = the_name_of_each_method_to_intercept;
18        }
19
20        public TypeToProxy target { get; set; }
21
22        public void Intercept(IInvocation invocation)
23        {
24            set_return_value_for(invocation);
25            if (the_name_of_each_method_to_intercept.Contains(invocation.Method.Name)) return;
26            the_name_of_each_method_to_intercept.Add(invocation.Method.Name);
27        }
28
29        public IEnumerable<string> methods_to_intercept()
30        {
31            return the_name_of_each_method_to_intercept;
32        }
33
34        static void set_return_value_for(IInvocation invocation)
35        {
36            var return_type = invocation.Method.ReturnType;
37            if (return_type == typeof (void)) return;
38            invocation.ReturnValue = return_type.default_value();
39        }
40    }
41}