Last active
May 19, 2020 09:55
-
-
Save AndrewBuntsev/a3c230868e460b8c17c1d7d1f636f543 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /// | |
| /// ConfigurationElement with additional Id property | |
| /// | |
| public abstract class IdentifiableConfigurationElement : ConfigurationElement | |
| { | |
| public virtual string Id { get; } | |
| } | |
| /// | |
| /// Generic ConfigurationElementCollection | |
| /// | |
| public class ConfigurationElementCollection<T> : ConfigurationElementCollection where T : IdentifiableConfigurationElement, new() | |
| { | |
| public T this[int index] | |
| { | |
| get { return (T)BaseGet(index); } | |
| set | |
| { | |
| if (BaseGet(index) != null) | |
| { | |
| BaseRemoveAt(index); | |
| } | |
| BaseAdd(index, value); | |
| } | |
| } | |
| public void Add(T serviceConfig) | |
| { | |
| BaseAdd(serviceConfig); | |
| } | |
| public void Clear() | |
| { | |
| BaseClear(); | |
| } | |
| protected override ConfigurationElement CreateNewElement() | |
| { | |
| return new T(); | |
| } | |
| protected override object GetElementKey(ConfigurationElement element) | |
| { | |
| return ((T)element).Id; | |
| } | |
| public void Remove(T serviceConfig) | |
| { | |
| BaseRemove(serviceConfig.Id); | |
| } | |
| public void RemoveAt(int index) | |
| { | |
| BaseRemoveAt(index); | |
| } | |
| public void Remove(String name) | |
| { | |
| BaseRemove(name); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment