The Labs \ Source Viewer \ SSCLI \ System.CodeDom.Compiler \ CompilerError

  1. //------------------------------------------------------------------------------
  2. // <copyright file="CompilerError.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.CodeDom.Compiler
  16. {
  17.     using System;
  18.     using System.CodeDom;
  19.     using System.Security.Permissions;
  20.     using System.Globalization;
  21.    
  22.    
  23.     /// <devdoc>
  24.     /// <para>
  25.     /// Represents a compiler error.
  26.     /// </para>
  27.     /// </devdoc>
  28.     [Serializable()]
  29.     [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")]
  30.     public class CompilerError
  31.     {
  32.         private int line;
  33.         private int column;
  34.         private string errorNumber;
  35.         private bool warning = false;
  36.         private string errorText;
  37.         private string fileName;
  38.        
  39.         /// <devdoc>
  40.         /// <para>
  41.         /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerError'/>.
  42.         /// </para>
  43.         /// </devdoc>
  44.         public CompilerError()
  45.         {
  46.             this.line = 0;
  47.             this.column = 0;
  48.             this.errorNumber = string.Empty;
  49.             this.errorText = string.Empty;
  50.             this.fileName = string.Empty;
  51.         }
  52.         /// <devdoc>
  53.         /// <para>
  54.         /// Initializes a new instance of <see cref='System.CodeDom.Compiler.CompilerError'/> using the specified
  55.         /// filename, line, column, error number and error text.
  56.         /// </para>
  57.         /// </devdoc>
  58.         public CompilerError(string fileName, int line, int column, string errorNumber, string errorText)
  59.         {
  60.             this.line = line;
  61.             this.column = column;
  62.             this.errorNumber = errorNumber;
  63.             this.errorText = errorText;
  64.             this.fileName = fileName;
  65.         }
  66.        
  67.         /// <devdoc>
  68.         /// <para>
  69.         /// Gets or sets the line number where the source of the error occurs.
  70.         /// </para>
  71.         /// </devdoc>
  72.         public int Line {
  73.             get { return line; }
  74.             set { line = value; }
  75.         }
  76.        
  77.         /// <devdoc>
  78.         /// <para>
  79.         /// Gets or sets the column number where the source of the error occurs.
  80.         /// </para>
  81.         /// </devdoc>
  82.         public int Column {
  83.             get { return column; }
  84.             set { column = value; }
  85.         }
  86.        
  87.         /// <devdoc>
  88.         /// <para>
  89.         /// Gets or sets the error number.
  90.         /// </para>
  91.         /// </devdoc>
  92.         public string ErrorNumber {
  93.             get { return errorNumber; }
  94.             set { errorNumber = value; }
  95.         }
  96.        
  97.         /// <devdoc>
  98.         /// <para>
  99.         /// Gets or sets the text of the error message.
  100.         /// </para>
  101.         /// </devdoc>
  102.         public string ErrorText {
  103.             get { return errorText; }
  104.             set { errorText = value; }
  105.         }
  106.        
  107.         /// <devdoc>
  108.         /// <para>
  109.         /// Gets or sets
  110.         /// a value indicating whether the error is a warning.
  111.         /// </para>
  112.         /// </devdoc>
  113.         public bool IsWarning {
  114.             get { return warning; }
  115.             set { warning = value; }
  116.         }
  117.        
  118.         /// <devdoc>
  119.         /// <para>
  120.         /// Gets or sets the filename of the source that caused the error.
  121.         /// </para>
  122.         /// </devdoc>
  123.         public string FileName {
  124.             get { return fileName; }
  125.             set { fileName = value; }
  126.         }
  127.        
  128.         /// <devdoc>
  129.         /// <para>
  130.         /// Overrides Object's ToString.
  131.         /// </para>
  132.         /// </devdoc>
  133.         public override string ToString()
  134.         {
  135.             if (FileName.Length > 0) {
  136.                 return string.Format(CultureInfo.InvariantCulture, "{0}({1},{2}) : {3} {4}: {5}", new object[] {FileName, Line, Column, IsWarning ? "warning" : "error", ErrorNumber, ErrorText});
  137.             }
  138.             else
  139.                 return string.Format(CultureInfo.InvariantCulture, "{0} {1}: {2}", IsWarning ? "warning" : "error", ErrorNumber, ErrorText);
  140.         }
  141.     }
  142. }

Developer Fusion