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);
Console.WriteLine("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);
}
Console.WriteLine(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

最新文章

  1. 28-React state提升、组件组合或继承
  2. [转]windows 短文件名/短路径名规则
  3. js除法四舍五入保留小数点后两位写法
  4. Aspose.word总结
  5. Android开发之ContentProvider(内容提供者)
  6. 静态代理VS动态代理
  7. bzoj1863
  8. memcached学习——常用命令+基于java客户端的3种简单实现(二)
  9. poj2409 Let it Bead
  10. android屏蔽home键的实现
  11. BNU OJ 50998 BQG's Messy Code
  12. Python[小甲鱼006常用操作符]
  13. C++如何返回不定长数组
  14. 二 Array 数组常用操作方法
  15. Linux extmail的邮件服务器搭建
  16. fmt.Sprintf格式化使用
  17. SQL Server 怎么在分页获取数据的同时获取到总记录数
  18. WinDbg 之 SOS扩展命令
  19. 一个nginx服务器配置多站点
  20. CQ3

热门文章

  1. Ubuntu源更新
  2. JQuery直接调用asp.net后台WebMethod方法(转)
  3. Event 同步机制
  4. 安装nodejs+npm的体验
  5. 深入Guerrilla Games解密次世代开山大作《杀戮地带暗影坠落》(The technology of Killzone Shadow Fall)
  6. canvas 绘制图像
  7. (五)js数组方法二
  8. 分布式缓冲之memcache
  9. ACM学习历程—HDU5700 区间交(树状数组 && 前缀和 && 排序)
  10. NOIP2013DAY1题解