Search code examples
c#debuggingattributesdebug-symbols

Can I create an attribute which will be stripped out of release code?


I want to do something like this:

[Notes("Remember to blah blah blah")]
public class Foo {

  [Notes("Redo this to include blah blah")]
  public string Bar { get; set; }

  // etc.

}

I know about the ConditionalAttribute, but it's sealed so I can't subclass my NotesAttribute from it.

Can this be done?


Solution

  • Yes this can be done!

    See my related question and answer here.

    You need to do this:

    [Conditional("DEBUG")]
    public class NotesAttribute : Attribute { }