Here's the error I'm getting with the code pasted below.
Unable to create instance of class ZDRCreatorTests.ZDRCreatorTests. Error: System.Configuration.ConfigurationErrorsException: The default value of the property 'indexedFolder' cannot be parsed. The error is: Unable to find a converter that supports conversion to/from string for the property 'indexedFolder' of type 'DirectoryInfo'..
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; }
}
}
}
I realize the error is because I'm trying to put a string in a DirectoryInfo object. My question is this: Am I suppose to only store strings or primitive data types read from the xml, then convert them to other objects once the xml is read? OR, is there a place where I can go ahead and construct them into the object that will be used internally. Where will validation of the input occur?