MibException.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Created by SharpDevelop.
  3. * User: lextm
  4. * Date: 2008/5/17
  5. * Time: 16:33
  6. *
  7. * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8. */
  9. using System;
  10. using System.Globalization;
  11. #if (!SILVERLIGHT)
  12. using System.Runtime.Serialization;
  13. using System.Security.Permissions;
  14. #endif
  15. namespace Lextm.SharpSnmpLib.Mib
  16. {
  17. /// <summary>
  18. /// Description of MibException.
  19. /// </summary>
  20. [Serializable]
  21. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mib")]
  22. public sealed class MibException : Exception
  23. {
  24. /// <summary>
  25. /// Symbol.
  26. /// </summary>
  27. public Symbol Symbol { get; private set; }
  28. /// <summary>
  29. /// Creates a <see cref="MibException"/>.
  30. /// </summary>
  31. public MibException()
  32. {
  33. }
  34. /// <summary>
  35. /// Creates a <see cref="SnmpException"/> instance with a specific <see cref="string"/>.
  36. /// </summary>
  37. /// <param name="message">Message</param>
  38. public MibException(string message) : base(message)
  39. {
  40. }
  41. /// <summary>
  42. /// Creates a <see cref="MibException"/> instance with a specific <see cref="string"/> and an <see cref="Exception"/>.
  43. /// </summary>
  44. /// <param name="message">Message</param>
  45. /// <param name="inner">Inner exception</param>
  46. public MibException(string message, Exception inner)
  47. : base(message, inner)
  48. {
  49. }
  50. #if (!SILVERLIGHT)
  51. /// <summary>
  52. /// Creates a <see cref="MibException"/> instance.
  53. /// </summary>
  54. /// <param name="info">Info</param>
  55. /// <param name="context">Context</param>
  56. private MibException(SerializationInfo info, StreamingContext context) : base(info, context)
  57. {
  58. if (info == null)
  59. {
  60. throw new ArgumentNullException("info");
  61. }
  62. Symbol = (Symbol)info.GetValue("Symbol", typeof(Symbol));
  63. }
  64. /// <summary>
  65. /// Gets object data.
  66. /// </summary>
  67. /// <param name="info">Info</param>
  68. /// <param name="context">Context</param>
  69. [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
  70. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  71. {
  72. base.GetObjectData(info, context);
  73. info.AddValue("Symbol", Symbol);
  74. }
  75. #endif
  76. /// <summary>
  77. /// Creates a <see cref="MibException"/> with a specific <see cref="Symbol"/>.
  78. /// </summary>
  79. /// <param name="message">Message</param>
  80. /// <param name="symbol">Symbol</param>
  81. /// <returns></returns>
  82. public static MibException Create(string message, Symbol symbol)
  83. {
  84. if (symbol == null)
  85. {
  86. throw new ArgumentNullException("symbol");
  87. }
  88. if (String.IsNullOrEmpty(message))
  89. {
  90. message = "Unknown MIB Exception";
  91. }
  92. message = String.Format(
  93. "{0} (file: \"{1}\"; row: {2}; column: {3})",
  94. message,
  95. symbol.File,
  96. symbol.Row + 1,
  97. symbol.Column + 1);
  98. MibException ex = new MibException(message) { Symbol = symbol };
  99. return ex;
  100. }
  101. }
  102. }