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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="ConfigXmlReader.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.Configuration.Internal;
  18.     using System.Collections;
  19.     using System.Collections.Specialized;
  20.     using System.Collections.Generic;
  21.     using System.Configuration;
  22.     using System.Globalization;
  23.     using System.IO;
  24.     using System.Runtime.InteropServices;
  25.     using System.Security;
  26.     using System.Security.Permissions;
  27.     using System.Text;
  28.     using System.Xml;
  29.     using System.Net;
  30.    
  31.     internal sealed class ConfigXmlReader : XmlTextReader, IConfigErrorInfo
  32.     {
  33.         string _rawXml;
  34.         int _lineOffset;
  35.         string _filename;
  36.        
  37.         // Used in a decrypted configuration section to locate
  38.         // the line where the ecnrypted section begins.
  39.         bool _lineNumberIsConstant;
  40.        
  41.         internal ConfigXmlReader(string rawXml, string filename, int lineOffset) : this(rawXml, filename, lineOffset, false)
  42.         {
  43.         }
  44.        
  45.         internal ConfigXmlReader(string rawXml, string filename, int lineOffset, bool lineNumberIsConstant) : base(new StringReader(rawXml))
  46.         {
  47.            
  48.             _rawXml = rawXml;
  49.             _filename = filename;
  50.             _lineOffset = lineOffset;
  51.             _lineNumberIsConstant = lineNumberIsConstant;
  52.            
  53.             Debug.Assert(!_lineNumberIsConstant || _lineOffset > 0, "!_lineNumberIsConstant || _lineOffset > 0");
  54.         }
  55.        
  56.         internal ConfigXmlReader Clone()
  57.         {
  58.             return new ConfigXmlReader(_rawXml, _filename, _lineOffset, _lineNumberIsConstant);
  59.         }
  60.        
  61.         int IConfigErrorInfo.LineNumber {
  62.             get {
  63.                 if (_lineNumberIsConstant) {
  64.                     return _lineOffset;
  65.                 }
  66.                 else if (_lineOffset > 0) {
  67.                     return base.LineNumber + (_lineOffset - 1);
  68.                 }
  69.                 else {
  70.                     return base.LineNumber;
  71.                 }
  72.             }
  73.         }
  74.        
  75.         string IConfigErrorInfo.Filename {
  76.             get { return _filename; }
  77.         }
  78.        
  79.         internal string RawXml {
  80.             get { return _rawXml; }
  81.         }
  82.     }
  83. }

Developer Fusion