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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ConfigurationSection.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. namespace System.Configuration
  16. {
  17.     using System;
  18.     using System.Collections.Specialized;
  19.     using System.Configuration.Internal;
  20.     using System.IO;
  21.     using System.Reflection;
  22.     using System.Security;
  23.     using System.Text;
  24.     using System.Xml;
  25.     using System.Globalization;
  26.    
  27.     public abstract class ConfigurationSection : ConfigurationElement
  28.     {
  29.        
  30.         private SectionInformation _section;
  31.        
  32.         // Constructor
  33.         //
  34.         protected ConfigurationSection()
  35.         {
  36.             _section = new SectionInformation(this);
  37.         }
  38.        
  39.         // SectionInformation property
  40.         //
  41.         // Retrieve the class associated with the Section information
  42.         //
  43.         public SectionInformation SectionInformation {
  44.             get { return _section; }
  45.         }
  46.        
  47.         // GetRuntimeObject
  48.         //
  49.         // Return the Runtime Object for this Section
  50.         //
  51.         protected internal virtual object GetRuntimeObject()
  52.         {
  53.             return this;
  54.         }
  55.        
  56.        
  57.         protected internal override bool IsModified()
  58.         {
  59.             return (SectionInformation.IsModifiedFlags() || base.IsModified());
  60.         }
  61.        
  62.         protected internal override void ResetModified()
  63.         {
  64.             SectionInformation.ResetModifiedFlags();
  65.             base.ResetModified();
  66.         }
  67.        
  68.         protected internal virtual void DeserializeSection(XmlReader reader)
  69.         {
  70.             if (!reader.Read() || reader.NodeType != XmlNodeType.Element) {
  71.                 throw new ConfigurationErrorsException(SR.GetString(SR.Config_base_expected_to_find_element), reader);
  72.             }
  73.             DeserializeElement(reader, false);
  74.         }
  75.        
  76.         protected internal virtual string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
  77.         {
  78.             ValidateElement(this, null, true);
  79.            
  80.             ConfigurationElement TempElement = CreateElement(this.GetType());
  81.             TempElement.Unmerge(this, parentElement, saveMode);
  82.            
  83.             StringWriter strWriter = new StringWriter(CultureInfo.InvariantCulture);
  84.             XmlTextWriter writer = new XmlTextWriter(strWriter);
  85.             writer.Formatting = Formatting.Indented;
  86.             writer.Indentation = 4;
  87.             writer.IndentChar = ' ';
  88.             TempElement.DataToWriteInternal = (saveMode != ConfigurationSaveMode.Minimal);
  89.             TempElement.SerializeToXmlElement(writer, name);
  90.             writer.Flush();
  91.             return strWriter.ToString();
  92.         }
  93.     }
  94. }

Developer Fusion