【发布时间】:2011-01-17 04:45:16
【问题描述】:
这是我在粘贴下面的代码时遇到的错误。
无法创建类 ZDRCreatorTests.ZDRCreatorTests 的实例。错误:System.Configuration.ConfigurationErrorsException:无法解析属性“indexedFolder”的默认值。错误是:找不到支持“DirectoryInfo”类型的属性“indexedFolder”的字符串转换为/从字符串转换的转换器..
namespace ZDRCreator
{
public class ZDRCreatorElement : ConfigurationElement
{
// Create the element.
public ZDRCreatorElement()
{ }
// Get or set the IndexedFolder
[ConfigurationProperty("indexedFolder", DefaultValue = "", IsRequired = true)]
public DirectoryInfo IndexedFolder {
get { return (DirectoryInfo)this["indexedFolder"]; }
set { this["indexedFolder"] = value; }
}
// Get or set the OutputFolder
[ConfigurationProperty("outputFolder", DefaultValue = "", IsRequired = true)]
public DirectoryInfo OutputFolder {
get { return (DirectoryInfo)this["outputFolder"]; }
set { this["outputFolder"] = value; }
}
// Get or set the ZDRFile
[ConfigurationProperty("ZDRFile", DefaultValue = "", IsRequired = true)]
public FileInfo ZDRFile {
get { return (FileInfo)this["ZDRFile"]; }
set { this["ZDRFile"] = value; }
}
// Get or set the overwriteOutput flag
[ConfigurationProperty("overwriteOutput", DefaultValue = "false", IsRequired = true)]
public bool OverwriteOutput {
get { return (bool)this["overwriteOutput"]; }
set { this["overwriteOutput"] = value; }
}
// Get or set the OutputFile
[ConfigurationProperty("outputFile", DefaultValue = "", IsRequired = true)]
public String OutputFile {
get { return (String)this["outputFile"]; }
set { this["outputFile"] = value; }
}
// Get or set the OutputFile
[ConfigurationProperty("pathMask", DefaultValue = "", IsRequired = true)]
public String PathMask {
get { return (String)this["pathMask"]; }
set { this["pathMask"] = value; }
}
}
}
我意识到错误是因为我试图将字符串放入 DirectoryInfo 对象中。我的问题是:我想只存储从 xml 读取的字符串或原始数据类型,然后在读取 xml 后将它们转换为其他对象吗?或者,是否有一个地方我可以继续并将它们构造成将在内部使用的对象。输入验证将在哪里进行?
【问题讨论】:
标签: c# xml configuration