我在配置文件中有以下键,我想将“添加键”从配置文件动态传递到我的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" />
请告知。
答案 0 :(得分:1)
您应该这样使用它:
//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"));