मैं एक क्लास वाली है निम्नलिखित ConfigurationSection:क्या मैं एक कस्टम कॉन्फ़िगरेशनसेक्शन पर IntegerValidator विशेषता के साथ एक सीमा निर्दिष्ट कर सकता हूं?
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 was unhandled
The value for the property 'waitForTimeSeconds' is not valid. The error is: The value must be inside the range 1-100.
मैं चान हैं जीई IntegerValidator
, एक ExcludeRage = सच है की मैं (जाहिर है) मिलता है:
ConfigurationErrorsException was unhandled
The value for the property 'waitForTimeSeconds' is not valid. The error is: The value must not be in the range 1-100
मैं तो एक नंबर 100 से अधिक करने के लिए .config में संपत्ति के मूल्य बदलते हैं, तो यह काम करता है।
यदि मैं वैधता को बदलता हूं तो केवल MaxValue
में से 100 यह काम करता है, लेकिन -1 का मान भी स्वीकार करेगा।
क्या इस तरह की सीमा के साथ IntegerValidatorAttribute
का उपयोग करना संभव है? जोड़ने के लिए
संपादित
एक issue by Microsoft के रूप में पुष्टि की है।
माइक्रोसॉफ्ट लिंक को आज समाधान के साथ अपडेट किया गया है। स्पष्ट रूप से यदि कोई डिफ़ॉल्ट मान निर्दिष्ट नहीं है, तो यह डिफ़ॉल्ट मान के रूप में "0" का उपयोग करता है। 0, निश्चित रूप से, सीमा 1-100 के बाहर है। "समाधान" सीमा में मौजूद डिफ़ॉल्ट मान के साथ ConfigProperty विशेषता में DefaultValue = पैरामीटर जोड़ना है। दुर्भाग्यवश इसका मतलब है कि आप एक डिफ़ॉल्ट मान लगा रहे हैं जो शायद आप चाहते हैं/आवश्यकता नहीं हो। मुझे यह समस्या भी हो रही है। खुशी है कि मैं इस सवाल पर ठोकर खाई! – Skrud