The Labs \ Source Viewer \ SSCLI \ System.Xml \ IXmlLineInfo

  1. //------------------------------------------------------------------------------
  2. // <copyright file="IXmlLineInfo.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.Xml
  16. {
  17.     /// <include file='doc\IXmlLineInfo.uex' path='docs/doc[@for="IXmlLineInfo"]/*' />
  18.     public interface IXmlLineInfo
  19.     {
  20.         /// <include file='doc\IXmlLineInfo.uex' path='docs/doc[@for="IXmlLineInfo.HasLineInfo"]/*' />
  21.         bool HasLineInfo();
  22.         /// <include file='doc\IXmlLineInfo.uex' path='docs/doc[@for="IXmlLineInfo.LineNumber"]/*' />
  23.         int LineNumber {
  24.             get;
  25.         }
  26.         /// <include file='doc\IXmlLineInfo.uex' path='docs/doc[@for="IXmlLineInfo.LinePosition"]/*' />
  27.         int LinePosition {
  28.             get;
  29.         }
  30.     }
  31.    
  32.     internal class PositionInfo : IXmlLineInfo
  33.     {
  34.         public virtual bool HasLineInfo()
  35.         {
  36.             return false;
  37.         }
  38.         public virtual int LineNumber {
  39.             get { return 0; }
  40.         }
  41.         public virtual int LinePosition {
  42.             get { return 0; }
  43.         }
  44.        
  45.         public static PositionInfo GetPositionInfo(object o)
  46.         {
  47.             IXmlLineInfo li = o as IXmlLineInfo;
  48.             if (li != null) {
  49.                 return new ReaderPositionInfo(li);
  50.             }
  51.             else {
  52.                 return new PositionInfo();
  53.             }
  54.         }
  55.     }
  56.    
  57.     internal class ReaderPositionInfo : PositionInfo
  58.     {
  59.         private IXmlLineInfo lineInfo;
  60.        
  61.         public ReaderPositionInfo(IXmlLineInfo lineInfo)
  62.         {
  63.             this.lineInfo = lineInfo;
  64.         }
  65.        
  66.         public override bool HasLineInfo()
  67.         {
  68.             return lineInfo.HasLineInfo();
  69.         }
  70.        
  71.         public override int LineNumber {
  72.             get { return lineInfo.LineNumber; }
  73.         }
  74.        
  75.         public override int LinePosition {
  76.             get { return lineInfo.LinePosition; }
  77.         }
  78.        
  79.     }
  80. }
  81. // namespace

Developer Fusion