开发者

Is there a way to inject code at build time?

I want to inject the following line into the top of every method of my application

Trace.WriteLine(this.GetType().Name + "." + "Name of Method");

I'd like to do it at compile time or build time or post-build - basically before it gets into customer's hands.

Is this po开发者_如何学Cssible?


You should look into PostSharp which is designed for this sort of thing. I don't know whether it's got an attribute for exactly that use case already, but I would guess it wouldn't be hard to write one.

EDIT: Another thought is to try using Mono.Cecil which is a binary rewriter. I haven't used it myself, but it's worth a try.


Yeah, you would use attributes for that, and as the Jon said, you could use PostSharp which is a great api for working easily with attributes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜