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

推荐订阅源

GbyAI
GbyAI
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
D
Docker
Blog — PlanetScale
Blog — PlanetScale
罗磊的独立博客
美团技术团队
V
V2EX
Last Week in AI
Last Week in AI
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Microsoft Security Blog
Microsoft Security Blog
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
M
MIT News - Artificial intelligence
P
Proofpoint News Feed
B
Blog RSS Feed
博客园_首页
B
Blog
博客园 - 叶小钗
I
InfoQ
WordPress大学
WordPress大学
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
The Register - Security
The Register - Security
MyScale Blog
MyScale Blog
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Latest news
Latest news
W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
News and Events Feed by Topic
S
Secure Thoughts
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News

博客园 - rex

C#编译javascript - JQuery模板 将C#编译为javascript TouchPad App - Advanced Calculator TouchPad App - Unit converter webOS App - Simple Unit Convert 在javascript库中整合Sizzle(Sizzle引擎的使用) source code upload to google code RexStudio2.0RC c# 2.0 Factory的实现 Emit生成Property C#2.0 Singleton 的实现 .NET 分布式事务处理 Castle IoC castle 五子棋:) *.ashx:HttpHandler的另一种用法 自己制作的ORMap框架终于完成的差不多了。 VStudio 2003 remote debug Application Container
AOP static crosscutting 的一个实现
rex · 2005-07-07 · via 博客园 - rex

        AOP的动态拦截已经有太多的文章了,但关于静态横切的实现却比较少,因此,我想提供一个实现思路来达到抛砖引玉的目的。
        实现的思想主要如下:
        将需要weave-in的源代码写入一个文件(例如 log.aspect),然后拦截new操作符(这可以参考其他人的文章,用ProxyAttribute加从MarshalByRefObject继承)或者构造的时候采用factory模式,返回要生成的对象的继承类,这里我采用的是生成一个临时的源文件,并采用CodeDom中的动态编译。基本上临时文件代码如下:

public class aop_Target : Target
{
//此处插入要weave-in的代码(从*.aspect中读取),例如
//public void Log(string msg)
//{
//  
//}
}

这样的实现比较简单,但效率一定是比较差的,相信采用Emit会有很大的提高。

最后,Weave-in的方法的调用只能采用反射加Invoke,这大概是一个比较大的弱点,但在完全采用C#编译器的前提下,大概也只能做到这样了。