C# AOP实现
2009-05-05 16:33
253 查看
using System; using System.Collections.Generic; using System.Text; using System.Runtime.Remoting.Proxies; namespace Aop { public class AopAttribute : ProxyAttribute { public override MarshalByRefObject CreateInstance(Type serverType) { AopProxy realProxy = new AopProxy(serverType); return realProxy.GetTransparentProxy() as MarshalByRefObject; } } }
AopProxy.cs
using System; using System.Collections.Generic; using System.Text; using System.Reflection.Emit; using System.Runtime.Remoting.Proxies; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Activation; using System.Windows.Forms; namespace Aop { public class AopProxy : RealProxy { public AopProxy(Type serverType) : base(serverType) { } public override IMessage Invoke(IMessage msg) { if (msg is IConstructionCallMessage) { IConstructionCallMessage constructCallMsg = msg as IConstructionCallMessage; IConstructionReturnMessage constructionReturnMessage = this.InitializeServerObject((IConstructionCallMessage)msg); RealProxy.SetStubData(this, constructionReturnMessage.ReturnValue); MessageBox.Show("Call constructor"); return constructionReturnMessage; } else { IMethodCallMessage callMsg = msg as IMethodCallMessage; IMessage message; try { object[] args = callMsg.Args; object o = callMsg.MethodBase.Invoke(GetUnwrappedServer(), args); message = new ReturnMessage(o, args, args.Length, callMsg.LogicalCallContext, callMsg); } catch (Exception e) { message = new ReturnMessage(e, callMsg); } MessageBox.Show(message.Properties["__Return"].ToString()); return message; } } } }
AopAttribute.cs
using System; using System.Collections.Generic; using System.Text; namespace Aop { [AopAttribute] public class AopClass : ContextBoundObject { public string Hello() { return "welcome"; } } }
AopClass.cs
相关文章推荐
- C# 用Attribute实现AOP事务
- C# 用Attribute实现AOP事务 [C# | AOP | Attribute | ContextAttribute | IContributeObjectSink | IMessageSink ]
- C# 用delegate实现AOP事务[C# | AOP | delegate]
- 颠覆C#王权的“魔比斯环” — 实现AOP框架的终极利器
- C# 用Attribute实现AOP事务 [C# | AOP | Attribute | ContextAttribute | IContributeObjectSink | IMessageSink
- 利用C#实现AOP常见的几种方法详解
- C# AOP手动实现
- 颠覆C#王权的“魔比斯环” — 实现AOP框架的终极利器
- Emit实现简单的C# AOP框架
- C#实现AOP框架
- 使用PostSharp在.NET平台上实现AOP (c# AOP)
- 关于在C#中实现AOP 拦截编程模式的新的探索
- 利用Attribute给C#实现AOP?
- C# 实现AOP 的几种常见方式
- C#利用Emit反射实现AOP,以及平台化框架封装思路
- 【C# / Pattern】C#中利用Attribute实现AOP(面向切面编程)
- C# 实现AOP 的几种常见方式
- AOP面向切面变成和C#实现多种实现
- C#当中利用Attribute实现简易AOP
- 利用C#实现AOP常见的几种方法详解