Skip to content

Configuration

Heromyth edited this page Jun 5, 2018 · 2 revisions

test.config

app.name = Hunt
app.version = 1.0
app.description = Shanghai Putao Ltd.

[dev]
app.buildMode = dev

[release]
app.buildMode = release

Settings model

@Configuration("app")
class TestConfig
{
    string name = "Kiss";
    string buildMode = "dev";
    @Value("version")
    string ver = "1.0";

    @property void description(string d)  {  _desc = d;   }
    @property string description()  { return _desc; }
    private string _desc = "Putao Ltd.";
}

Demo

ConfigBuilder builder = new ConfigBuilder("test.config", "release");
TestConfig config = builder.build!(TestConfig)();

assert(config.name == "Hunt", config.name);
assert(config.ver == "1.0", config.ver);
assert(config.buildMode == "release", config.buildMode);
assert(config.description == "Shanghai Putao Ltd.", config.description);
Clone this wiki locally