The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl \ SourceLineInfo

  1. //------------------------------------------------------------------------------
  2. // <copyright file="SourceLineInfo.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.Diagnostics;
  16. namespace System.Xml.Xsl
  17. {
  18.    
  19.     [DebuggerDisplay("{uriString} [{startLine},{startPos} -- {endLine},{endPos}]")]
  20.     internal class SourceLineInfo : ISourceLineInfo
  21.     {
  22.         private string uriString;
  23.         private int startLine;
  24.         private int startPos;
  25.         private int endLine;
  26.         private int endPos;
  27.        
  28.         public SourceLineInfo(string uriString, int startLine, int startPos, int endLine, int endPos)
  29.         {
  30.             this.uriString = uriString;
  31.             this.startLine = startLine;
  32.             this.startPos = startPos;
  33.             this.endLine = endLine;
  34.             this.endPos = endPos;
  35.         }
  36.        
  37.         public string Uri {
  38.             get { return this.uriString; }
  39.         }
  40.         public int StartLine {
  41.             get { return this.startLine; }
  42.         }
  43.         public int StartPos {
  44.             get { return this.startPos; }
  45.         }
  46.         public int EndLine {
  47.             get { return this.endLine; }
  48.         }
  49.         public int EndPos {
  50.             get { return this.endPos; }
  51.         }
  52.        
  53.         internal void SetEndLinePos(int endLine, int endPos)
  54.         {
  55.             this.endLine = endLine;
  56.             this.endPos = endPos;
  57.         }
  58.        
  59.         /// <summary>
  60.         /// Magic number 0xfeefee is used in PDB to denote a section of IL that does not map to any user code.
  61.         /// When VS debugger steps into IL marked with 0xfeefee, it will continue the step until it reaches
  62.         /// some user code.
  63.         /// </summary>
  64.         private const int NoSourceMagicNumber = 16707566;
  65.        
  66.         public static SourceLineInfo NoSource = new SourceLineInfo(string.Empty, NoSourceMagicNumber, 0, NoSourceMagicNumber, 0);
  67.        
  68.         public bool IsNoSource {
  69.             get { return this.startLine == NoSourceMagicNumber; }
  70.         }
  71.        
  72.         [Conditional("DEBUG")]
  73.         public static void Validate(ISourceLineInfo lineInfo)
  74.         {
  75.             if (lineInfo.StartLine == 0 || lineInfo.StartLine == NoSourceMagicNumber) {
  76.                 Debug.Assert(lineInfo.StartLine == lineInfo.EndLine);
  77.                 Debug.Assert(lineInfo.StartPos == 0 && lineInfo.EndPos == 0);
  78.             }
  79.             else {
  80.                 Debug.Assert(0 < lineInfo.StartLine && lineInfo.StartLine <= lineInfo.EndLine);
  81.                 if (lineInfo.StartLine == lineInfo.EndLine) {
  82.                     Debug.Assert(0 < lineInfo.StartPos && lineInfo.StartPos < lineInfo.EndPos);
  83.                 }
  84.                 else {
  85.                     Debug.Assert(0 < lineInfo.StartPos && 0 < lineInfo.EndPos);
  86.                 }
  87.             }
  88.         }
  89.        
  90.         // Returns file path for local and network URIs. Used for PDB generating and error reporting.
  91.         public static string GetFileName(string uriString)
  92.         {
  93.             Uri uri;
  94.            
  95.             if (uriString.Length != 0 && System.Uri.TryCreate(uriString, UriKind.Absolute, out uri) && uri.IsFile) {
  96.                 return uri.LocalPath;
  97.             }
  98.             return uriString;
  99.         }
  100.     }
  101. }

Developer Fusion