惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Blog of Author Tim Ferriss
S
Securelist
D
Docker
The Register - Security
The Register - Security
GbyAI
GbyAI
Recorded Future
Recorded Future
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
罗磊的独立博客
博客园 - 【当耐特】
F
Full Disclosure
WordPress大学
WordPress大学
腾讯CDC
小众软件
小众软件
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
I
InfoQ
MyScale Blog
MyScale Blog
量子位
Cyberwarzone
Cyberwarzone
博客园 - 三生石上(FineUI控件)
The Hacker News
The Hacker News
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
博客园_首页
H
Help Net Security
K
Kaspersky official blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Webroot Blog
Webroot Blog
Blog — PlanetScale
Blog — PlanetScale
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
The Cloudflare Blog
P
Proofpoint News Feed
V
Visual Studio Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
爱范儿
爱范儿
P
Privacy International News Feed
Security Archives - TechRepublic
Security Archives - TechRepublic
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog RSS Feed

博客园 - 分享

暂时搬迁到轻博客, 点点 很有创意的AkShell:用JS开发web,轻松发布 emacs最重要的一个命令 多语言多范型编程PPP Hobo扩展了rails的功能 scala by example这本没出版的书感觉不错的 非常快的文本模式的emacs 学习正则表达式的好网站 Rebular emacs开发rails的演示 rails采用MongoDB感觉相当不错! 尝试用博客找工作,发一个求职 DrX:可视化的ruby对象模型 ruby koans:tdd方式学习ruby infoq对CouchDB创始人的访谈 不错的erlang,haskell入门,英文版 infoq 对ruby创始人Matz的访谈 linux桌面的时代已经到了 转:一个土木工程师在四川地震灾后的思考 天台宗:六即佛诵
10分钟入门AOP:用PostSharp普及一下AOP
分享 · 2008-03-22 · via 博客园 - 分享

PostSharp是一个比较强调易学易用的AOP框架,在这之前我接触过AspectJ,Spring.当然花的时间也不多,不过一直感觉不好掌握,似乎AOP是比较难的东西。今天看到这篇英文论文里面的说明,似乎并不那么难以掌握。参考下图,对比一下两组概念。


PS用了我们熟知的东西,而没有引入新名词,这是它聪明的地方。看表格右边的一组概念,事件(还不太理解为什么说是meta),事件处理器,aspect=定制的attribute, 唯一新鲜的是multicasting,实际上可以理解为一个通配表达式。

下面再用一个简单例子:

public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry (MethodExecutionEventArgs eventArgs )
{  Console . WriteLine (" Entering the method {0}." , eventArgs . Method );
}

public override void OnExit (MethodExecutionEventArgs eventArgs )
{
  Console . WriteLine (
" Leaving the method {0}." , eventArgs . Method );
}

}


class Program
{
[Log]
static void Main ()
{
    Console . WriteLine (" Hello , world .");
}
}

//multicasting 说明对

MyApp . BusinessObjects命名空间使用Log

[ assembly : Log(
AttributeTargetTypes =
" MyApp . BusinessObjects .*" ,
AttributeTargetMemberAttributes =
MulticastAttributes . Public )]

从这例子看非常简明清晰,的确易学易用。

分享:practice makes perfect.