The Labs \ Source Viewer \ SSCLI \ System.Configuration \ NameValueConfigurationCollection

  1. //------------------------------------------------------------------------------
  2. // <copyright file="NameValueConfigurationCollection.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. /*
  16. * ImmutableCollections
  17. *
  18. * Copyright (c) 2004 Microsoft Corporation
  19. */
  20. using System;
  21. using System.Collections;
  22. using System.Collections.Specialized;
  23. using System.Net;
  24. using System.Configuration;
  25. //
  26. // This file contains configuration collections that are used by multiple sections
  27. //
  28. namespace System.Configuration
  29. {
  30.    
  31.     [ConfigurationCollection(typeof(NameValueConfigurationElement))]
  32.     public sealed class NameValueConfigurationCollection : ConfigurationElementCollection
  33.     {
  34.         private static ConfigurationPropertyCollection _properties;
  35.        
  36.         static NameValueConfigurationCollection()
  37.         {
  38.             // Property initialization
  39.             _properties = new ConfigurationPropertyCollection();
  40.         }
  41.        
  42.         protected internal override ConfigurationPropertyCollection Properties {
  43.             get { return _properties; }
  44.         }
  45.         //
  46.         // Constructor
  47.         //
  48.         public NameValueConfigurationCollection()
  49.         {
  50.         }
  51.        
  52.         //
  53.         // Accessors
  54.         //
  55.        
  56.         public new NameValueConfigurationElement this[string name]
  57.         {
  58.             get { return (NameValueConfigurationElement)BaseGet(name); }
  59.             set {
  60.                 int index = -1;
  61.                 // append by default
  62.                 NameValueConfigurationElement tempElement = (NameValueConfigurationElement)BaseGet(name);
  63.                 if (tempElement != null) {
  64.                     index = BaseIndexOf(tempElement);
  65.                     BaseRemoveAt(index);
  66.                 }
  67.                 BaseAdd(index, value);
  68.             }
  69.         }
  70.        
  71.         public string[] AllKeys {
  72.             get { return StringUtil.ObjectArrayToStringArray(BaseGetAllKeys()); }
  73.         }
  74.        
  75.         //
  76.         // Methods
  77.         //
  78.        
  79.         public void Add(NameValueConfigurationElement nameValue)
  80.         {
  81.             BaseAdd(nameValue);
  82.         }
  83.         public void Remove(NameValueConfigurationElement nameValue)
  84.         {
  85.             if (BaseIndexOf(nameValue) >= 0)
  86.                 BaseRemove(nameValue.Name);
  87.         }
  88.         public void Remove(string name)
  89.         {
  90.             BaseRemove(name);
  91.         }
  92.         public void Clear()
  93.         {
  94.             BaseClear();
  95.         }
  96.         protected override ConfigurationElement CreateNewElement()
  97.         {
  98.             return new NameValueConfigurationElement();
  99.         }
  100.         protected override object GetElementKey(ConfigurationElement element)
  101.         {
  102.             return ((NameValueConfigurationElement)element).Name;
  103.         }
  104.     }
  105. }

Developer Fusion