所以我对使用 app-config 文件完全陌生,我试图创建一个自定义配置处理程序,以便我可以从同一个键中读取多个值,我按照 Microsoft 网站上的文档进行操作,但遇到了问题。
每次我尝试运行我的代码时,它都会抛出这个错误
“无法识别的属性‘数据类型’。请注意,属性名称区分大小写。(C:\Users\stephen.carmody\Desktop\FlatFileFactory - Copy\FlatFileFactory\bin\Debug\FlatFileFactory.vshost.exe.Config 第 21 行)”
它似乎只识别元素中的前两个值,第三个“数据类型”抛出错误
这是我的配置文件
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- Configuration section-handler declaration area. -->
<configSections>
<sectionGroup name="propertyValuesGroup">
<section
name="propertyValues"
type="FlatFileTestCaseAutomater.CustomConfigurationSectionHandler,FlatFileFactory"
allowLocation="true"
allowDefinition="Everywhere"
/>
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<!-- Configuration section settings area. -->
<propertyValuesGroup>
<propertyValues>
<cHeaderProperty name="txnNo" nullable="yes" datatype="int" maxlength="" />
</propertyValues>
</propertyValuesGroup>
</configuration>
这是我的自定义处理程序类:
namespace FlatFileTestCaseAutomater
{
class CustomConfigurationSectionHandler : ConfigurationSection
{
[ConfigurationProperty("cHeaderProperty")]
public CHeaderPropertyElement Property
{
get
{
return (CHeaderPropertyElement)this["cHeaderProperty"];
}
set
{ this["cHeaderProperty"] = value; }
}
}
public class ClaimHeaderElement : ConfigurationElement
{
[ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
[StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String Name
{
get
{
return (String)this["name"];
}
set
{
this["name"] = value;
}
}
[ConfigurationProperty("dataType", DefaultValue = "", IsRequired = true)]
[StringValidator(InvalidCharacters = "~!@#$%^&*()[]{}/;'\"|\\", MinLength = 1, MaxLength = 60)]
public String DataType
{
get
{
return (String)this["dataType"];
}
set
{
this["dataType"] = value;
}
}
[ConfigurationProperty("maxLength", DefaultValue = int.MaxValue, IsRequired = false)]
// [IntegerValidator(ExcludeRange = false, MaxValue = 24, MinValue = 0)]
public int MaxLength
{
get
{ return (int)this["maxLength"]; }
set
{ this["maxLength"] = value; }
}
}
}
这是调试期间发生中断的代码片段:
FlatFileTestCaseAutomater.CustomConfigurationSectionHandler config =
(FlatFileTestCaseAutomater.CustomConfigurationSectionHandler)System.Configuration.ConfigurationManager.GetSection(
"propertyValuesGroup/propertyValues");
我知道之前已经发布过类似的帖子,但我已经在这几个小时没有运气了