To match the execution environment " development (for develop) ", " production (for release) " and is a constant used in the system ,
There is a lot to change .
This is possible to achieve in a feat of strength , such as " commenting out the source code ," but , in the maintenance surface
  • It is difficult to grasp the constant to be switched
  • If there is more than one constant , switching leak -prone
It means that there is a problem , such as , can lead to trouble , which is not needed .
It has developed a MConfig in order to solve this problem .


  • Define ( development and production ) environment , you can define a constant environment to another .
  • At runtime, you can define which one to use environment .
  • There is no limit to the number or constant name .
  • It is not possible to change dynamically the execution environment .

Configuration Example

Describe the following in app.config.
<?xml version="1.0" encoding="utf-8" ?>

    <section name="mconfig" type="MConfig.MConfigSectionHandler, MConfig"/>

    <!--execution environment-->
    <execution name="develop"/>

    <!--environment list-->
      <!--for develop-->
      <environment name="develop">
          <setting name="FTPServer" value="localhost" tag="FTP" />
          <setting name="FTPUser" value="anonymous" tag="FTP"/>
          <setting name="FTPPassword" value="" tag="FTP"/>
          <setting name="DBServer" value="" tag="DB" />
          <setting name="DBUser" value="debuguser" tag="DB"/>
          <setting name="DBPassword" value="debugpassword" tag="DB"/>

      <!--for release-->
      <environment name="release">
          <setting name="FTPServer" value="x.x.x.x" tag="FTP" />
          <setting name="FTPUser" value="xxxxxxx" tag="FTP" />
          <setting name="FTPPassword" value="xxxxxxx" tag="FTP" />
          <setting name="DBServer" value="y.y.y.y" tag="DB" />
          <setting name="DBUser" value="yyyyyyy" tag="DB" />
          <setting name="DBPassword" value="yyyyyyy" tag="DB" />


Execution element

  • Name
Execution environment name . Required .
Please specify the name of the environment element .

Environment element

  • Name
Environment name . Required .
It is a good idea to use debug, develop, usertest, and release.

Setting element

  • Name
Configuration name . Required .
  • Value
Setting . Required .
  • Tag
Tag . Any .
It does not refer to the same value in the framework side .
Because it is passed as an argument to the event hook at the time , please use the branching process .


Get the execution environment name


Get value

Can be obtained by passing the configuration name argument of GetConfigValue.
MConfigReader.Instance.ReadValue ("FTPServer")

Tips for using the practical

Code snippet does not work when accessing the constant

It does not work on specification .
Create a wrapper class , you may want to access by way of the ( property ) or the same class .
For more information, please refer to the Test project that comes with your source code .

※ For testing purposes , Test is not a code of utility only . Please consider one of Tsudatoo idea .

Plain text is displayed as it is I in trouble

It does not support it directly beyond the scope of this framework with respect to security , and it does not even guarantee .
However , it can be applied the following method . Please consider .
  • I want to encrypt the application configuration file
  • It is possible to set a string that has been encrypted in the application configuration file on , to decode at the same event by the hook OnReadConfigValue event of MConfigReader class .


I is compatible with NuGet. Please refer to the following sites for more information .

Last edited Apr 19, 2014 at 2:28 AM by mk3008, version 1