पेरेंट तत्व (और नहीं एक बच्चे संग्रह तत्व) के भीतर सीधे बैठने के लिए अपने संग्रह तत्वों सक्षम करने के लिए, आप अपने ConfigurationProperty
फिर से परिभाषित करने की जरूरत है।
public class TestConfigurationElement : ConfigurationElement
{
[ConfigurationProperty("name", IsKey = true, IsRequired = true)]
public string Name
{
get { return (string)this["name"]; }
}
}
और एक संग्रह जैसे::
[ConfigurationCollection(typeof(TestConfigurationElement), AddItemName = "test")]
public class TestConfigurationElementCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new TestConfigurationElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((TestConfigurationElement)element).Name;
}
}
मैं के रूप में माता पिता के अनुभाग/तत्व निर्धारित करने होंगे:
public class TestConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("", IsDefaultCollection = true)]
public TestConfigurationElementCollection Tests
{
get { return (TestConfigurationElementCollection)this[""]; }
}
}
जैसे, मान लीजिए कि मैं इस तरह के रूप में एक संग्रह तत्व डालते हैं [ConfigurationProperty("", IsDefaultCollection = true)]
विशेषता पर ध्यान दें।
<testConfig>
<test name="One" />
<test name="Two" />
</testConfig>
के बजाय
: यह एक खाली नाम देते हुए और डिफ़ॉल्ट संग्रह के रूप में सेट मुझे मेरे config की तरह परिभाषित करने के लिए अनुमति देता है
<testConfig>
<tests>
<test name="One" />
<test name="Two" />
</tests>
</testConfig>
स्रोत
2011-06-11 08:32:40
यदि ये उत्तर पूरी तरह से आपकी सहायता नहीं करते हैं, तो कृपया अतिरिक्त जानकारी प्रदान करें ताकि हम और सहायता कर सकें। – Haukman