因此,我编写了一个自定义配置处理程序,以允许我为 app-config 文件中的单个键分配多个值。我现在所拥有的作品,但仅适用于一个元素。我得到的错误是我尝试多次使用相同的元素,但是我知道这应该完全可以使用自定义配置处理程序。
任何见解将不胜感激
这是我的一些相关代码:App - Config
<configSections>
<sectionGroup name="propertyValuesGroup">
<section
name="propertyValues"
type="FlatFileTestCaseAutomater.ClaimHeaderSection,FlatFileFactory"
allowLocation="true"
allowDefinition="Everywhere"
/>
</sectionGroup>
<!-- Other <section> and <sectionGroup> elements. -->
</configSections>
<!-- Configuration section settings area. -->
<propertyValuesGroup>
<propertyValues>
<claimHeader name="txnNo" nullable="yes" dataType="int" maxLength="20" />
<claimHeader name="batchNo" nullable="yes" dataType="string" maxLength="20" />
</propertyValues>
</propertyValuesGroup>
</configuration>
.
.
.
. 我的自定义配置处理程序类:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Xml;
namespace FlatFileTestCaseAutomater
{
class ClaimHeaderSection : ConfigurationSection
{
[ConfigurationProperty("claimHeader")]
public ClaimHeaderElement ClaimHeaderProperty
{
get
{
return (ClaimHeaderElement)this["claimHeader"];
}
set
{ this["claimHeader"] = value; }
}
}
public class ClaimHeaderElement : ConfigurationElement
{
[ConfigurationProperty("name", DefaultValue = "", IsRequired = true)]
public String Name
{
get
{
return (String)this["name"];
}
set
{
this["name"] = value;
}
}
[ConfigurationProperty("nullable", DefaultValue = "yes", IsRequired = true)]
public String Nullable
{
get
{
return (String)this["nullable"];
}
set
{
this["nullable"] = value;
}
}
[ConfigurationProperty("dataType", DefaultValue = "", IsRequired = true)]
public String DataType
{
get
{
return (String)this["dataType"];
}
set
{
this["dataType"] = value;
}
}
[ConfigurationProperty("maxLength", DefaultValue = "", IsRequired = true)]
public string MaxLength
{
get
{ return (string)this["maxLength"]; }
set
{ this["maxLength"] = value; }
}
}
}
. . . .
并调用这些值:
latFileTestCaseAutomater.ClaimHeaderSection config =
(FlatFileTestCaseAutomater.ClaimHeaderSection)System.Configuration.ConfigurationManager.GetSection(
"propertyValuesGroup/propertyValues");