XmlException.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // XmlException.cs
  3. //
  4. // Author:
  5. // Jason Diamond ([email protected])
  6. //
  7. // (C) 2002 Jason Diamond http://injektilo.org/
  8. //
  9. using System;
  10. using System.Runtime.Serialization;
  11. namespace System.Xml
  12. {
  13. [Serializable]
  14. public class XmlException : SystemException
  15. {
  16. #region Fields
  17. int lineNumber;
  18. int linePosition;
  19. #endregion
  20. #region Constructors
  21. public XmlException (string message, Exception innerException)
  22. : base (message, innerException)
  23. {
  24. }
  25. protected XmlException (SerializationInfo info, StreamingContext context)
  26. : base (info, context)
  27. {
  28. this.lineNumber = info.GetInt32 ("lineNumber");
  29. this.linePosition = info.GetInt32 ("linePosition");
  30. }
  31. internal XmlException (string message)
  32. : base (message)
  33. {
  34. }
  35. internal XmlException (IXmlLineInfo li, string message) : base (message)
  36. {
  37. if (li != null) {
  38. this.lineNumber = li.LineNumber;
  39. this.linePosition = li.LinePosition;
  40. }
  41. }
  42. internal XmlException (string message, int lineNumber, int linePosition) : base (message)
  43. {
  44. this.lineNumber = lineNumber;
  45. this.linePosition = linePosition;
  46. }
  47. #endregion
  48. #region Properties
  49. public int LineNumber {
  50. get { return lineNumber; }
  51. }
  52. public int LinePosition {
  53. get { return linePosition; }
  54. }
  55. public override string Message {
  56. get {
  57. if (lineNumber == 0)
  58. return base.Message;
  59. return String.Format ("{0} Line {1}, position {2}.",
  60. base.Message, lineNumber, linePosition);
  61. }
  62. }
  63. #endregion
  64. #region Methods
  65. public override void GetObjectData (SerializationInfo info, StreamingContext context)
  66. {
  67. base.GetObjectData (info, context);
  68. info.AddValue ("lineNumber", lineNumber);
  69. info.AddValue ("linePosition", linePosition);
  70. }
  71. #endregion
  72. }
  73. }