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

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 分享

暂时搬迁到轻博客, 点点 很有创意的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.