Insert file or DB value into compilation constant (Visual Basic)

67 views Asked by At

imagine the following code in VB.NET:

#Const TestCode = True
#If TestCode Then
  Console.WriteLine("Test code enabled.")
#Else
  Console.WriteLine("No test code.")
#End If

These conditions are executed in compilation time, but now I'm trying to give to the constant TestCode a value from a file or a database. The idea is to be able to change that constant value in run-time without the need of updating the software in production.

Anyone knows how to do that?

Thanks

1

There are 1 answers

0
Paul Abbott On

#if conditionally compiles the contained block of code, so if TestCode = True, then Console.WriteLine("No test code.") is not even compiled. There would be no way to "switch over to it" at runtime because that line of code would not exist in the application binary. Why not just use a regular if instead of compiler directives?