title: Easiest way to inject code to all methods and properties that don't have a custom attribute
body: <p>There are a a lot of questions and answers around <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" rel="nofollow">AOP</a> in <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="nofollow">.NET</a> here on Stack&nbsp;Overflow, often mentioning PostSharp and other third-party products. So there seems to be quite a range of AOP optons in the .NET and C# world. But each of those has their restrictions, and after downloading the promising PostSharp <strike>I found in their documentation that 'methods have to be virtual' in order to be able to inject code</strike> (edit: see ChrisWue's answer and my comment - the virtual constraint must have been on one of the contenders, I suppose). I haven't investigated the accuracy of this statement any further, but it's categoricality made me return back to Stack&nbsp;Overflow.</p>
  
  <p>So I'd like to get an answer to this very specific question:</p>
  
  <p>I want to <strong>inject simple</strong> "if (some-condition) Console.WriteLine" style <strong>code to every method and property</strong> (static, sealed, internal, virtual, non-virtual, doesn't matter) <strong>in my project that does not have a custom annotation</strong>, in order to dynamically test my software at run-time. This injected code should not remain in the release build, it is just meant for dynamic testing (thread-related) during development.</p>
  
  <p>What's the easiest way to do this? I stumbled upon <a href="http://www.mono-project.com/Cecil" rel="nofollow">Mono.Cecil</a>, which looks ideal, except that you seem to have to write the code that you want to inject in IL. This isn't a huge problem, it's easy to use Mono.Cecil to get an IL version of code written in C#. But nevertheless, if there was something simpler, ideally even built into .NET (I'm still on .NET 3.5), I'd like to know. <strong>[Update: If the suggested tool is not part of the .NET Framework, it would be nice if it was open-source, like Mono.Cecil, or freely available]</strong></p>