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.
精彩评论