CompilationException.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // System.Web.Compilation.CompilationException
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. //
  7. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Collections;
  31. using System.CodeDom.Compiler;
  32. using System.Text;
  33. using System.Web;
  34. namespace System.Web.Compilation
  35. {
  36. internal class CompilationException : HtmlizedException
  37. {
  38. string filename;
  39. CompilerErrorCollection errors;
  40. string fileText;
  41. string errmsg;
  42. int [] errorLines;
  43. public CompilationException (string filename, CompilerErrorCollection errors, string fileText)
  44. {
  45. this.filename = filename;
  46. this.errors = errors;
  47. this.fileText = fileText;
  48. }
  49. public override string SourceFile {
  50. get {
  51. if (errors == null || errors.Count == 0)
  52. return filename;
  53. return errors [0].FileName;
  54. }
  55. }
  56. public override string FileName {
  57. get { return filename; }
  58. }
  59. public override string Title {
  60. get { return "Compilation Error"; }
  61. }
  62. public override string Description {
  63. get {
  64. return "Error compiling a resource required to service this request. " +
  65. "Review your source file and modify it to fix this error.";
  66. }
  67. }
  68. public override string ErrorMessage {
  69. get {
  70. if (errmsg == null && errors != null) {
  71. StringBuilder sb = new StringBuilder ();
  72. foreach (CompilerError err in errors) {
  73. sb.Append (err);
  74. sb.Append ("\n");
  75. }
  76. errmsg = sb.ToString ();
  77. }
  78. return errmsg;
  79. }
  80. }
  81. public override string FileText {
  82. get { return fileText; }
  83. }
  84. public override int [] ErrorLines {
  85. get {
  86. if (errorLines == null && errors != null) {
  87. ArrayList list = new ArrayList ();
  88. foreach (CompilerError err in errors) {
  89. if (err.Line != 0 && !list.Contains (err.Line))
  90. list.Add (err.Line);
  91. }
  92. errorLines = (int []) list.ToArray (typeof (int));
  93. Array.Sort (errorLines);
  94. }
  95. return errorLines;
  96. }
  97. }
  98. public override bool ErrorLinesPaired {
  99. get { return false; }
  100. }
  101. }
  102. }