稍微变化一下!注意区别。

Program.cs

class Program
{
  static void Main(string[] args)
  {
    User user = " };
    var processor = TransparentProxy.Create(new UserProcessor());
    processor.Shopping(user);
    Console.ReadLine();
  }
}

User.cs

public class User
{
  public string Name { get; set; }

  public string Password { get; set; }
}

IUserProcessor.cs

public interface IUserProcessor
{
  void Shopping(User user);
}

UserProcessor.cs

public class UserProcessor : IUserProcessor
{
  public void Shopping(User user)
  {
    Console.WriteLine("买呀,买呀,买桃子!");
  }
}

UserProxyProcessor.cs

class UserProxyProcessor<T> : RealProxy
{
  private T processor;

  public UserProxyProcessor(T processor) :
    base(typeof(T))//不能丢
  {
    this.processor = processor;
  }

  public override IMessage Invoke(IMessage msg)
  {
    PreShopping();
    IMethodCallMessage message = (IMethodCallMessage)msg;
    object result = message.MethodBase.Invoke(processor, message.Args);
    PostShopping();
    ], , null, message);
  }

  private void PreShopping()
  {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("买东西前,判断是否注册了!");
    Console.ResetColor();
  }

  private void PostShopping()
  {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("买完东西后,写个日志文件!");
    Console.ResetColor();
  }
}

TransparentProxy.cs

public static class TransparentProxy
{
  public static IUserProcessor Create(IUserProcessor obj)
  {
    var processor = new UserProxyProcessor<IUserProcessor>(obj);
    IUserProcessor transparentProxy = (IUserProcessor)processor.GetTransparentProxy();
    return transparentProxy;
  }
}

RealProxy实现AOP编程(2)的更多相关文章

  1. RealProxy实现AOP编程(1)

    Program.cs class Program { static void Main(string[] args) { User user = " }; var processor = T ...

  2. .Net中的RealProxy实现AOP

    序言 这个AOP要从我们公司的一个事故说起,前段时间公司的系统突然在乌云中出现,数据被泄露的一览无余,乌云上显示是SQL注入攻击.呵,多么贴近生活的一个露洞,可谓是人尽皆知啊.然而却华丽丽的给拉我们一 ...

  3. 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入

    概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...

  4. 使用spring方式来实现aop编程

    1:什么是aop? Aspect Oriented Programming 面向切面编程 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...

  5. Spring学习笔记之四----基于Annotation的Spring AOP编程

    你能使用@Aspect annotation将某个Java类标注为Aspect,这个Aspect类里的所有公有方法都可以成为一个Advice,Spring提供了5个Annotation去将某个方法标注 ...

  6. 聊Javascript中的AOP编程

    Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...

  7. 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--AOP编程

    AOP编程在目前来说好像是大家都比较喜欢的.ASP.NET MVC中的Filter就是使用AOP实现的配置器模式.AOP在编码中的应用主要有如下几个方面: 日志记录,跟踪,优化和监控 事务的处理 持久 ...

  8. struts2.1笔记03:AOP编程和拦截器概念的简介

    1.AOP编程 AOP编程,也叫面向切面编程(也叫面向方面):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容.利用A ...

  9. Method Swizzling以及AOP编程:在运行时进行代码注入-备用

    概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...

随机推荐

  1. 织梦系统dedecms如何开启伪静态

    做为一名网站建设工程师,必须要考虑到网站优化方面的工作,那么选择CMS系统的时候,有良好的网站 优化功能就是一个好的CMS的标准之一,而系统是否支持伪静态,则是URL优化的工作之一,而织梦系统能良好的 ...

  2. 列王的纷争,COK,675区,有去的没有?加群:159108918,盟的名字准备叫:大话西游

    首先我承认我玩物丧志了 679区,有去的没有?加群: 474574809,盟的名字叫:Moon Box 如何练最强5级号,为新区做准备?! 粮食是可以为0的,士兵不会死,这是关键之一. 关键之二是新手 ...

  3. 【转】responseText,responseBody,responseXML差别

    为了做ajax的代理,研究了下服务器端的xmlhttp和客户端ajax中的xmlhttp,做了个比较 由于我一直使用JavaScript作为Asp的教本语言,所以比较起来更清楚.服务器端的xmlhtt ...

  4. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)

    题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...

  5. error MSB6006: “CL.exe”已退出,代码为X —— 的解决办法

    错误 : error MSB6006: “CL.exe”已退出,代码为X . 解决方法: 1.有少可能是执行目录引起的. 参考 http://bbs.csdn.net/topics/370064083 ...

  6. Linux 内核常见宏定义

    我们在阅读Linux内核是,常见到这些宏 __init, __initdata, __initfunc(), asmlinkage, ENTRY(), FASTCALL()等等.它们定义在 /incl ...

  7. java读取大文件

    1  多线程 2  java内存映射读取大文件

  8. linux内核学习之四 系统调用

    一  概念区分 提到linux系统调用,不得不区分几个比较容易混淆的概念: 系统调用:系统调用就是一种特殊的接口.通过这个接口,用户可以访问内核空间.系统调用规定了用户进程进入内核的具体位置. 应用程 ...

  9. git 小结

    git cherry-pick de0ec64  可将另一个分支中的提交 cherry-pick到当前分支来

  10. 课程笔记:——javascript中的预解释2

    in:检测某一个属性是否属于这个对象(既可以检测私有的属性,也可以检测公有的属性) --> attr in obj 1.不管条件是否成立,在预解释的时候,判断体中的带var和function的都 ...