FileNotFoundException.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // System.IO.FileNotFoundException.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. // Duncan Mak ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc. http://www.ximian.com
  9. //
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Runtime.Serialization;
  13. namespace System.IO {
  14. [Serializable]
  15. public class FileNotFoundException : IOException {
  16. private string fileName;
  17. private string fusionLog;
  18. // Constructors
  19. public FileNotFoundException ()
  20. : base (Locale.GetText ("File not found"))
  21. {
  22. }
  23. public FileNotFoundException (string message)
  24. : base (message)
  25. {
  26. }
  27. public FileNotFoundException (string message, Exception inner)
  28. : base (message, inner)
  29. {
  30. }
  31. public FileNotFoundException (string message, string fileName)
  32. : base (message)
  33. {
  34. this.fileName = fileName;
  35. }
  36. public FileNotFoundException (string message, string fileName, Exception innerException)
  37. : base (message, innerException)
  38. {
  39. this.fileName = fileName;
  40. }
  41. protected FileNotFoundException (SerializationInfo info, StreamingContext context)
  42. : base (info, context)
  43. {
  44. fileName = info.GetString ("FileNotFound_FileName");
  45. fusionLog = info.GetString ("FileNotFound_FusionLog");
  46. }
  47. public string FileName
  48. {
  49. get { return fileName; }
  50. }
  51. public string FusionLog
  52. {
  53. get { return fusionLog; }
  54. }
  55. public override string Message
  56. {
  57. get {
  58. if (base.Message == null)
  59. return "File not found";
  60. if (fileName == null)
  61. return base.Message;
  62. return "File '" + fileName + "' not found.";
  63. }
  64. }
  65. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  66. {
  67. base.GetObjectData (info, context);
  68. info.AddValue ("FileNotFound_FileName", fileName);
  69. info.AddValue ("FileNotFound_FusionLog", fusionLog);
  70. }
  71. public override string ToString ()
  72. {
  73. string result = GetType ().FullName + ": " + Message;
  74. if (InnerException != null)
  75. result += " ----> " + InnerException.ToString ();
  76. if (StackTrace != null)
  77. result += "\n" + StackTrace;
  78. return result;
  79. }
  80. }
  81. }