Yes, ConditionalAttribute
is a special case, being one of only a few attributes that are specifically handled directly by the compiler.
The compiler would have no well-defined behaviour in that case, so it chooses not to let you do it, to avoid confusion.
Of course, technically you could write a non-attribute class in MSIL that is marked with ConditionalAttribute
, compile that with ilasm
, and then reference it from a C# project - it would be interesting to know what the C# compiler does... I'm guessing it would do nothing special unless individual methods had the method too, since that is the scenario it targets.