is it possible to create 2 methods that have the same method-name, passed in values and returns using the conditional attribute and some anti conditional for example
[Conditional("Debug")]
private string StringGenerator()
{
Guid g = Guid.NewGuid();
string guidString = Convert.ToBase64String(g.ToByteArray());
guidString = guidString.Replace("=", "");
guidString = guidString.Replace("+", "");
return guidString;
}
[!Conditional("Debug")]// I know using '!' doesn't really work
private string StringGenerator()
{
Guid g = Guid.NewGuid();
string guidString = Convert.ToBase64String(g.ToByteArray());
return guidString;
}
so that you could just call a method and based on whether "Debug" is defined the compiler will choose which method?
Thanks
No this is not possible. The Conditional
attribute doesn't control whether or not a method is defined in code, it just controls the conditions under which the method call is included in the calling code.
Additionally it's possible for the Conditional
attribute to be applied multiple times to a method. Hence there isn't a simply on / off
decision to be made here. Consider
[Conditional("DEBUG")]
[Conditional("TRACE")]
void Target() { ... }
There are 4 combinations here to consider, not just 2.
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