0

我正在尝试阅读 Microsoft 定义的 ConfigurationSection:

Microsoft.ApplicationServer.Caching.DataCacheClientSection

但类型是内部的,所以我无法以传统方式访问它。

IE

var dataCacheClientSection = (DataCacheClientSection)ConfigurationManager.GetSection("dataCacheClient");

我知道我可以使用反射,但我还有其他选择吗?

4

1 回答 1

1

您可以将配置文件打开为 XmlDocument 并使用 XPath 读取您想要的任何内容。

就像是:

var xmlDoc = new XmlDocument();
xmlDoc.Load(Assembly.GetExecutingAssembly().Location + ".config");
XmlNode setting = xmlDoc.SelectSingleNode("configuration/...");

在 SelectSingleNode 中使用正确的 XPath

于 2011-11-21T09:39:27.790 回答