tags:

views:

93

answers:

5

Can I do something like this:

Configs.Environment.Development;

I'm currently doing something like this:

Configs.Environment == "DEV";

I don't particularly care for the strings, but I don't know how to set "specific" properties or if it's possible.

A: 

You could accomplish that by making Environment an enumeration or making Development a static readonly string.

Eric Mickelsen
A: 

Yes.

 public static class Configs{
         public static class Environment{
              public static readonly string Development="DEV";
          }

  }

But you probably want ENUMS, and use a factory to set your constants.

Nix
static readonly is preferable to const
Eric Mickelsen
@tehMick: Why would that be so?
dtb
because it sounds like he is "toggling" constants. It doesn't look like he just wants a list of properties to access.
Nix
http://blogs.msdn.com/b/davidklinems/archive/2006/10/27/const-vs-static-readonly.aspx
Mike Atlas
@dtb - the major reason is because if another project references the one with the `const`, then that project would have to be recompiled if the `const` value ever changed (since `const` values are substituted at compile time). `static readonly` members are evaluated at run-time so they don't have this issue.
John Rasch
+1  A: 

This sounds like the sort of thing that's better handled by a preprocessor directive:

#if debug
/* etc */
#elseif production
/* etc */
#endif
JSBangs
+3  A: 

Are you talking about enums?

public enum Environment
{
    Development,
    Test,
    Live
}


Configs.Environment = Environment.Development;
fearofawhackplanet
A: 

Do you want the setting to take effect at compile time only or at runtime? Do you want your user to be able to select different settings after deployment?

If you want a compile time only setting, then a pre-processor directive is what you want.

If you want runtime settings, .NET has direct support for .config files and you can access the values in your code (and set them too) via the Settings.Default constructs.

VisualStudio has support for easily creating and maintaining these config files.

AlfredBr