RealProxy实现AOP编程(2)
稍微变化一下!注意区别。
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)的更多相关文章
- RealProxy实现AOP编程(1)
Program.cs class Program { static void Main(string[] args) { User user = " }; var processor = T ...
- .Net中的RealProxy实现AOP
序言 这个AOP要从我们公司的一个事故说起,前段时间公司的系统突然在乌云中出现,数据被泄露的一览无余,乌云上显示是SQL注入攻击.呵,多么贴近生活的一个露洞,可谓是人尽皆知啊.然而却华丽丽的给拉我们一 ...
- 【原】iOS动态性(三) Method Swizzling以及AOP编程:在运行时进行代码注入
概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...
- 使用spring方式来实现aop编程
1:什么是aop? Aspect Oriented Programming 面向切面编程 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译 ...
- Spring学习笔记之四----基于Annotation的Spring AOP编程
你能使用@Aspect annotation将某个Java类标注为Aspect,这个Aspect类里的所有公有方法都可以成为一个Advice,Spring提供了5个Annotation去将某个方法标注 ...
- 聊Javascript中的AOP编程
Duck punch 我们先不谈AOP编程,先从duck punch编程谈起. 如果你去wikipedia中查找duck punch,你查阅到的应该是monkey patch这个词条.根据解释,Mon ...
- 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--AOP编程
AOP编程在目前来说好像是大家都比较喜欢的.ASP.NET MVC中的Filter就是使用AOP实现的配置器模式.AOP在编码中的应用主要有如下几个方面: 日志记录,跟踪,优化和监控 事务的处理 持久 ...
- struts2.1笔记03:AOP编程和拦截器概念的简介
1.AOP编程 AOP编程,也叫面向切面编程(也叫面向方面):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容.利用A ...
- Method Swizzling以及AOP编程:在运行时进行代码注入-备用
概述 今天我们主要讨论iOS runtime中的一种黑色技术,称为Method Swizzling.字面上理解Method Swizzling可能比较晦涩难懂,毕竟不是中文,不过你可以理解为“移花接木 ...
随机推荐
- H5之contenteditable
场景: <div id='content' contenteditable='true' > hello </div> <button id='caret'>设置光 ...
- js写的闹钟,支持多个闹钟
因为玩一个游戏,该游戏可以支持多个号,每个号有好多等时间的任务. 来回切换看,太耽误时间.手机的闹钟操作太麻烦. 所以写了一个使用配置文件的闹钟,简单方便. var ForReading = 1, F ...
- 【Python⑤】python序列---list和tuple
sequence 序列 sequence(序列)是一组有顺序的对象的集合.序列可以包含一个或多个元素,也可以没有任何元素. 我们之前所说的基本数据类型,都可以作为序列的对象.对象还可以是另一个序列.序 ...
- Bootstrap<基础十三> 按钮组
按钮组允许多个按钮被堆叠在同一行上.当你想要把按钮对齐在一起时,这就显得非常有用.你可以通过Bootstrap 按钮(Button) 插件 添加可选的 JavaScript 单选框和复选框样式行为. ...
- SpringMVC 文件上传&拦截器&异常处理
文件上传 Spring MVC 为文件上传提供了直接的支持,这种支持是通过即插即用的 MultipartResolver 实现的.Spring 用 Jakarta Commons FileUpload ...
- Git版本库
创建版本库:git init db 只要用git init db 就可以很容易创建一个空的Git版本库. Git版本库创建好之后,在版本库的目录下有一个.git的子目录中有几项内容,其中注意三项: 1 ...
- 自定义cell(xib)中button点击事件不能响应的情况
遇到这种问题真的好尴尬,之前从来没有遇到过,以为手到擒来,未曾料到还会遇到问题! 好多年没有找到尴尬的感觉,现在找到了,真的很尴尬 ! *o* 1.首先使用场景: 原本没打算用xib,后来为了快速, ...
- android 开发中 添加库文件 和so 文件的存放位置和添加依赖
so文件一般存储在 main 当中 jniLibs 当中 然后在build.gradle中添加 sourceSets { main { jniLibs.srcDirs = ['src/main/j ...
- A Brief Review of Supervised Learning
There are a number of algorithms that are typically used for system identification, adaptive control ...
- RankLib参数翻译
写在前面,metric2t指标详解: NDCG(Normalized discounted cumulative gain)即DCG/IDCGCG(cumulative gain)DCG(Discou ...