假设配置文件中有多个配置节,可以动态获取配置集合的内容吗?
System.Configuration.Configuration sysConfig = ConfigurationManager.OpenMappedExeConfiguration...
foreach (ConfigurationSection section in sysConfig.Sections)
{
Console.WriteLine(section.GetType().Name);
if (section.ElementInformation.IsCollection)
{
//How can I get the contents from the collection without knowing the type?
}
似乎该集合仅作为其创建的类中的一个属性公开。即在下面的配置部分中,获取插件作业的唯一方法是将对象强制转换为PluginJobsConfiguration类型,然后利用PluginJobs属性。有不知道类型的通用方法吗?
public class PluginJobsConfiguration: ConfigurationSection
{
[ConfigurationProperty("", IsDefaultCollection = true)]
public PluginJobConfigElementCollection PluginJobs
{
get { return (PluginJobConfigElementCollection)base[""]; }
}
}