【发布时间】:2011-01-20 07:03:05
【问题描述】:
我正在用 C# 和 .NET 3.5 编写自定义配置类。属性之一应为 System.Type 类型。当我运行代码时,我得到了标题中提到的错误。
[ConfigurationProperty("alertType", IsRequired = true)]
public Type AlertType
{
get { return (Type)this["alertType"]; }
set { this["alertType"] = value; }
}
配置文件如下所示:
<add name="Name" pollingInterval="60" alertType="Namespace.ClassName, Company.Project" />
.net 框架能够将字符串转换为 System.Type,因为配置文件的 configSections 具有类型属性。问题是他们是怎么做到的。
【问题讨论】: