从 app.config 文件动态传递密钥

Pass in Keys dynamic from app.config file

我在配置文件中有以下键,我想从配置文件中动态地将“添加键”传递到我的conn变量,我可以在我的conn变量中传递qp.cat.qmgr成功,我想知道我如何将其他键传递给我的变量我是否从 .config 传递下一个键,如 + "qp.cat.quser",即

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr") + ("qp.cat.quser") + ("qp.cat.qpassword"));

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr"), "theTestingUAT", "catquat"); //this works but "theTestingUAT" and "catquat" is hard coded, dont want them to be hardcoded

    <add key="qp.cat.qmgr" value="thetest:5444" />
    <add key="qp.cat.quser" value="theTestingUAT" />
    <add key="qp.cat.qpassword" value="catquat" />

请指教

你应该这样使用它:

//Helpers.AppSettings.Get<string>("qp.cat.qmgr")
//Helpers.AppSettings.Get<string>("qp.cat.quser")
//Helpers.AppSettings.Get<string>("qp.cat.qpassword")

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr"), Helpers.AppSettings.Get<string>("qp.cat.quser"), Helpers.AppSettings.Get<string>("qp.cat.qpassword"));