title: Generating a custom compile time warning C#
body: <p>I'm using VS2008 and would like to create a compile time warning / error based on custom attributes on a property (if it is possible).</p>
  <p>There are two cases which interest me currently:</p>
  <pre class="lang-cs prettyprint-override"><code>[MyAttribute (typeof(MyClass)]
  </code></pre>
  <p>Where <code>MyClass</code> has to implement an interface. Currently I assert this in the constructor of the attribute, however this doesn't make it easy to track down, due to the nature of the stack trace:</p>
  <pre class="lang-cs prettyprint-override"><code>public MyAttribute (Type MyClassType)
  {
      System.Diagnostics.Debug.Assert(
          typeof(MyInterface).IsAssignableFrom(MyClassType),
          &quot;Editor must implement interface: &quot; + typeof(MyInterface).Name);
  }
  </code></pre>
  <p>The second case which interests me is where I have a type defined in an attribute, if that type implements an interface, then a warning should be displayed if another attribute isn't present.</p>
  <p>I.E. <code>if (MyClass.Implements(SomeInterface) &amp;&amp; !Exists(SomeAttibute)) {  Generate Warning }</code></p>
  <pre class="lang-cs prettyprint-override"><code>[MyAttribute(typeof(MyClass)] 
  // Comment next line to generate warning
  [Foo (&quot;Bar&quot;)]
  </code></pre>
  <p>Thanks!</p>