From: hammett <ha...@uo...> - 2004-11-01 19:16:31
|
Hello, I got rid of all that creepy IL Emit Code in the proxy generator classes by developing a simple object model able to generate types, methods, properties, constructors, nested types and callables. It was very drive to DynamicProxy necessity, "do the simplest thing that could possible work". So the hundred lines code for WriteILMethod turned into the simplest form: protected virtual void WriteInterceptorInvocationMethod(MethodInfo method, EasyMethod builder) { ArgumentReference[] arguments = builder.Arguments; LocalReference local_inv = builder.CodeBuilder.DeclareLocal(typeof (IInvocation)); EasyCallable callable = m_method2Delegate[method] as EasyCallable; FieldReference fieldDelegate = ObtainCallableFieldBuilderDelegate( callable ); builder.CodeBuilder.AddStatement( new AssignStatement( local_inv, new VirtualMethodInvocationExpression(m_method2Invocation, fieldDelegate.ToExpression(), new MethodTokenExpression(method)) ) ); LocalReference ret_local = builder.CodeBuilder.DeclareLocal( typeof(object) ); builder.CodeBuilder.AddStatement( new AssignStatement( ret_local, new VirtualMethodInvocationExpression( InterceptorField, typeof (IInterceptor).GetMethod("Intercept"), local_inv.ToExpression(), new ReferencesToObjectArrayExpression(arguments)))); if (builder.ReturnType == typeof (void)) { builder.CodeBuilder.AddStatement( new ReturnStatement() ); } else { builder.CodeBuilder.AddStatement( new ReturnStatement( new ConvertExpression(builder.ReturnType, ret_local.ToExpression())) ); } } Oh, and btw all the serialization issues were fixed too. That was a long weekend. Phew! CodeBuilder http://www.digitalcraftsmen.com.br/svn/castle/trunk/Tools/DynamicProxy/DynamicProxy/Builder/CodeBuilder/ SimpleAST http://www.digitalcraftsmen.com.br/svn/castle/trunk/Tools/DynamicProxy/DynamicProxy/Builder/CodeBuilder/SimpleAST/ -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |