Question

Is there a possibility to use an class/method attribute only when a condtion is met? i.e. a registry in the system of a specific value or an app.config setting would indicate, if this custom attribute should be applied to a class? Thanks

Was it helpful?

Solution

No. You'd need to put that condition into whatever's using the attribute. The attribute is either applied to the member or not, unconditionally (as it's in the file itself).

Of course you can conditionally apply it or not apply it at compilation time, although doing that on the basis of a registry setting or app.config setting would require a bit of trickiness to change the build settings.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top