This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<configuration> | |
<configSections> | |
<section name="testConfig" type="Testy.ItemsConfigurationSection, Testy" /> | |
</configSections> | |
<testConfig> | |
<items> | |
<item name="One" /> | |
<item name="Two" /> | |
</items> | |
</testConfig> | |
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Testy | |
{ | |
public class ItemConfigurationElement : ConfigurationElement | |
{ | |
[ConfigurationProperty("name", IsKey = true, IsRequired = true)] | |
public string Name | |
{ | |
get { return (string)this["name"]; } | |
} | |
} | |
[ConfigurationCollection(typeof(ItemConfigurationElement), AddItemName = "item")] | |
public class ItemsConfigurationElementCollection : ConfigurationElementCollection | |
{ | |
protected override ConfigurationElement CreateNewElement() | |
{ | |
return new ItemConfigurationElement(); | |
} | |
protected override object GetElementKey(ConfigurationElement element) | |
{ | |
return ((ItemConfigurationElement)element).Name; | |
} | |
} | |
public class ItemsConfigurationSection : ConfigurationSection | |
{ | |
[ConfigurationProperty("items", IsDefaultCollection = true)] | |
public ItemsConfigurationElementCollection Tests | |
{ | |
get { return (ItemsConfigurationElementCollection)this["items"]; } | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
ItemsConfigurationSection configManager = (ItemsConfigurationSection)ConfigurationManager.GetSection("testConfig"); | |
var zmienna = configManager.Tests; | |
} | |
catch (Exception ex) | |
{ | |
throw; | |
} |
No comments:
Post a Comment