C# Conditional equivalent of !DEBUG -
this question has answer here:
- c# !conditional attribute? 6 answers
what c# system.diagnostics.conditional
equivalent of #if (!debug)
?
i want encrypt section of app.config file of console application if has not been compiled in debug mode. achieved so:
public static void main(string[] args) { #if (!debug) configencryption.encryptappsettings(); #endif //... }
but somehow, prefer decorating encrypt method conditional attribute:
[conditional("!debug")] internal static void encryptappsettings() { //... }
however makes compiler sad: the argument 'system.diagnostics.conditionalattribute' attribute must valid identifier...
what correct syntax negating conditional argument?
edit: @gusdor, used (i preferred keep program.cs file free of if/else debug logic):
#if !debug #define encrypt_config #endif [conditional("encrypt_config")] internal static void encryptappsettings() { //... }
using attribute bit of hack can done.
#if debug //you have nothing here c# requires #else #define not_debug //define symbol specifying non debug environment #endif [conditional("not_debug")] internal static void encryptappsettings() { //... }
Comments
Post a Comment