我有一个包含以下ConfigurationSection的类:
namespace DummyConsole {
class TestingComponentSettings: ConfigurationSection {
[ConfigurationProperty("waitForTimeSeconds", IsRequired=true)]
[IntegerValidator(MinValue = 1, MaxValue = 100, ExcludeRange = false)]
public int WaitForTimeSeconds
{
get { return (int)this["waitForTimeSeconds"]; }
set { this["waitForTimeSeconds"] = value; }
}
[ConfigurationProperty("loginPage", IsRequired = true, IsKey=false)]
public string LoginPage
{
get { return (string)this["loginPage"]; }
set { this["loginPage"] = value; }
}
}
}
然后,我的 .config 文件中有以下内容:
<configSections>
<section name="TestingComponentSettings"
type="DummyConsole.TestingComponentSettings, DummyConsole"/>
</configSections>
<TestingComponentSettings waitForTimeSeconds="20" loginPage="myPage" />
然后,当我尝试使用此配置部分时,出现以下错误:
var Testing = ConfigurationManager.GetSection("TestingComponentSettings")
as TestingComponentSettings;
ConfigurationErrorsException 未处理
属性“waitForTimeSeconds”的值无效。错误是:该值必须在 1-100 范围内。
如果我将其更改为IntegerValidator
ExcludeRage = true,我(显然)会得到:
ConfigurationErrorsException 未处理
属性“waitForTimeSeconds”的值无效。错误是:该值不能在 1-100 范围内
如果我随后将 .config 中的属性值更改为大于 100 的数字,它就可以工作。
如果我将验证器更改为只有MaxValue
100 它可以工作,但也会接受 -1 的值。
是否可以在IntegerValidatorAttribute
这样的范围内使用?
编辑以添加
Microsoft确认为问题。