üst öğesine (ve bir çocuk koleksiyonu öğe) içinde doğrudan oturmak için toplama elementleri sağlamak için, ConfigurationProperty
yeniden tanımlamak gerekir.
public class TestConfigurationElement : ConfigurationElement
{
[ConfigurationProperty("name", IsKey = true, IsRequired = true)]
public string Name
{
get { return (string)this["name"]; }
}
}
Ve bir koleksiyon gibi:
[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;
}
}
Ben ebeveyn bölümü/öğesini tanımlamak gerekir:
public class TestConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("", IsDefaultCollection = true)]
public TestConfigurationElementCollection Tests
{
get { return (TestConfigurationElementCollection)this[""]; }
}
}
Örneğin, bu reklam gibi bir koleksiyon öğesi var diyelim [ConfigurationProperty("", IsDefaultCollection = true)]
özniteliğine dikkat edin.
<testConfig>
<test name="One" />
<test name="Two" />
</testConfig>
yerine: o boş bir ad verilmesi ve varsayılan koleksiyonu olarak ayarlama beni gibi benim yapılandırma tanımlamanızı sağlar Kullanabileceğin düşünüyorum
<testConfig>
<tests>
<test name="One" />
<test name="Two" />
</tests>
</testConfig>
Bu cevaplar size tam olarak yardımcı olmazsa, daha fazla yardımcı olabilmemiz için lütfen ek bilgi sağlayın. – Haukman