I want to use the conditional attribute on a class, or more to the point, is there something that give that effect? Basically I don't want the class to be there in debug mode. I also don't want to have to wrap each call in a #if DEBUG
directive.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace NameSpace
{
[Conditional("Debug")]
public class ClassName
{
public ClassName()
{
}
}
}
A conditional attribute is a tag used to mark a method or class whose execution depends on the definition of preprocessing identifier. A conditional attribute indicates a condition to specify conditional compilation wherein methods are selectively called on the basis of definition of symbols.
No, there isn't. Conditional attributes don't make their targets disappear themselves - they just make the compiler omit users of the targets.
Eric Lippert had a post on just this sort of thing today, as it happens. Read it and see if it all makes more sense to you.
If you really need to omit the class itself in release mode, then use preprocessor directives - but you'll have to do the same for all the callers as well. What harm does it have to keep the class around in release mode, anyway?
Could this actually be a class in a different project? If so, then you could just apply the conditional attribute to all the methods, then the type wouldn't be needed in release mode, so you could avoid shipping the assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With