Annotating C# code in arbitrary levels without obfuscating the code too much?
<p>I'm looking for the best way to do the following in C#.</p>

<p>Say I have a certain set of instructions:</p>

<pre><code>int a = 1;
int b = 2;
if (a==b) {return;}
...
</code></pre>

<p>I need to get some information per instruction or sets of instructions. So I annotate the code, roughly as follows:</p>

<pre><code>Console.WriteLine("a");
int a = 1;
Console.WriteLine("a");
int b = 2;
Console.WriteLine("if");
if (a==b) {
 Console.WriteLine("ret");
  return;}
...
</code></pre>

<p>Now suppose I need to have much more complete information about each instruction, actually several classes with some methods, and I want to even pass some information to those classes. Annotating the code like that certainly obfuscates the code to a point where it's practically unreadable. Imagine lots of prints in-between instructions, for instance.</p>

<p>My question, finally, is: is there a way (would <code>[Attributes]</code> help here?) to annotate code with arbitrary levels of complexity of the annotations, without cluttering it? I can imagine something like attributes, which would look like </p>

<pre><code>[Class.variable("a")]
int a = 1;
[Class.variable("a")]
int b = 2;
[Class.instruction("if")]
if (a==b) {
  [Class.instruction("ret")]
  return;}
...
</code></pre>

<p>while each class does a lot of stuff? If the above example with atts work, could someone give me an example of how it would work "for real" and not in pseudocode?</p>

<p>Thanks very much.</p>
