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



我在配置文件中有以下密钥,我想从配置文件中动态地将"add key"传递到我的conn变量中,我可以成功地传递qp.cat.qmgr,在我的conn-variable中,我想知道我如何将其他密钥传递给我的变量。我应该像+"qp.cat.quser"一样从.config中传递下一个密钥吗,即

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"));

最新更新