MixIn Interfaces Proxy(その2)
時間が無いので以下のような、簡単なデモを書いて動かしてみた。
namespace DynamicProxy { public class MixedInProxyTest { [STAThread] static void Main(string args) { IMethodInterceptor interceptor = new TraceInterceptor(); IPointcut pointcut = new PointcutImpl(new string { ".*" }); IAspect aspects = new AspectImpl(interceptor, pointcut); DynamicAopProxy proxy1 = new DynamicAopProxy( new Type { typeof(ITest1), typeof(ITest2), typeof(ITest3) }, new IAspect { aspects }, null, new TestImpl()); ITest1 itest1 = proxy1.Create() as ITest1; itest1.TestFunctionOne("Hello ITest1"); ITest2 itest2 = itest1 as ITest2; itest2.TestFunctionTwo("Hello", "ITest2"); ITest3 itest3 = itest1 as ITest3; itest3.TestFunctionThree("Hello", "ITest3", "yah!"); System.Environment.Exit(0); } } public interface ITest1 { void TestFunctionOne(object a); } public interface ITest2 { object TestFunctionTwo(object a, object b); } public interface ITest3 { object TestFunctionThree(object a, object b, object c); } public class TestImpl : ITest1, ITest2, ITest3 { public virtual void TestFunctionOne(object a) { Console.WriteLine("TestFunctionOne(" + a + ")"); } public virtual object TestFunctionTwo(object a, object b) { Console.WriteLine("TestFunctionTwo(" + a +", " + b + ")"); return null; } public virtual object TestFunctionThree(object a, object b, object c) { Console.WriteLine("TestFunctionThree(" + a + ", " + b + ", " + c + ")"); return null; } } }
実行結果
BEGIN DynamicProxy.TestImpl#TestFunctionOne(Hello ITest1) TestFunctionOne(Hello ITest1) END DynamicProxy.TestImpl#TestFunctionOne(Hello ITest1) : BEGIN DynamicProxy.TestImpl#TestFunctionTwo(Hello, ITest2) TestFunctionTwo(Hello, ITest2) END DynamicProxy.TestImpl#TestFunctionTwo(Hello, ITest2) : BEGIN DynamicProxy.TestImpl#TestFunctionThree(Hello, ITest3, yah!) TestFunctionThree(Hello, ITest3, yah!) END DynamicProxy.TestImpl#TestFunctionThree(Hello, ITest3, yah!) :
とりあえずvirtualメソッドとinterfacexメソッドが重複することは無いようだ。s2ではどうだろう。