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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="PropertyInformationCollection.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. using System;
  16. using System.Configuration;
  17. using System.Collections.Specialized;
  18. using System.ComponentModel;
  19. using System.Collections;
  20. using System.Runtime.Serialization;
  21. using System.Security.Permissions;
  22. namespace System.Configuration
  23. {
  24.    
  25.     // PropertyInformationCollection
  26.     //
  27.     // Collection of PropertyInformation objects
  28.     //
  29.    
  30.     [Serializable()]
  31.     public sealed class PropertyInformationCollection : NameObjectCollectionBase
  32.     {
  33.         ConfigurationElement ThisElement = null;
  34.         internal PropertyInformationCollection(ConfigurationElement thisElement) : base(StringComparer.Ordinal)
  35.         {
  36.             ThisElement = thisElement;
  37.             foreach (ConfigurationProperty prop in ThisElement.Properties) {
  38.                 if (prop.Name != ThisElement.ElementTagName) {
  39.                     BaseAdd(prop.Name, new PropertyInformation(thisElement, prop.Name));
  40.                 }
  41.             }
  42.             IsReadOnly = true;
  43.         }
  44.        
  45.         [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
  46.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
  47.         {
  48.             base.GetObjectData(info, context);
  49.         }
  50.        
  51.         // Item
  52.         //
  53.         // Indexor for retrieving a Property by name
  54.         //
  55.         public PropertyInformation this[string propertyName]
  56.         {
  57.             get {
  58.                 PropertyInformation result = (PropertyInformation)BaseGet(propertyName);
  59.                
  60.                 // check for default collection name
  61.                 if (result == null) {
  62.                     PropertyInformation defaultColl = (PropertyInformation)BaseGet(ConfigurationProperty.DefaultCollectionPropertyName);
  63.                    
  64.                     if ((defaultColl != null) && (defaultColl.ProvidedName == propertyName)) {
  65.                         result = defaultColl;
  66.                     }
  67.                 }
  68.                 return result;
  69.             }
  70.         }
  71.        
  72.         internal PropertyInformation this[int index]
  73.         {
  74.             get { return (PropertyInformation)BaseGet(BaseGetKey(index)); }
  75.         }
  76.        
  77.         public void CopyTo(PropertyInformation[] array, int index)
  78.         {
  79.             if (array == null) {
  80.                 throw new ArgumentNullException("array");
  81.             }
  82.            
  83.             if (array.Length < Count + index) {
  84.                 throw new ArgumentOutOfRangeException("index");
  85.             }
  86.            
  87.             foreach (PropertyInformation pi in this) {
  88.                 array[index++] = pi;
  89.             }
  90.         }
  91.        
  92.        
  93.         public override IEnumerator GetEnumerator()
  94.         {
  95.             int c = Count;
  96.             for (int i = 0; i < c; i++) {
  97.                 yield return this[i];
  98.             }
  99.         }
  100.     }
  101. }

Developer Fusion