次の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 より大きい数値に変更すると、機能します。
バリデーターを 100 だけに変更するMaxValue
と動作しますが、-1 の値も受け入れます。
IntegerValidatorAttribute
このような範囲でを使用することは可能ですか?
編集して追加
Microsoft によって問題として確認されています。