开发者

C# Specific Properties

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.


Are you talking about enums?

public enum Environment
{
    Development,
    Test,
    Live
}


Configs.Environment = Environment.Development;


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

#if debug
/* etc */
#elseif production
/* etc */
#endif


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜