/* * Created by SharpDevelop. * User: lextm * Date: 2008/5/17 * Time: 16:33 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Globalization; #if (!SILVERLIGHT) using System.Runtime.Serialization; using System.Security.Permissions; #endif namespace Lextm.SharpSnmpLib.Mib { /// /// Description of MibException. /// [Serializable] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mib")] public sealed class MibException : Exception { /// /// Symbol. /// public Symbol Symbol { get; private set; } /// /// Creates a . /// public MibException() { } /// /// Creates a instance with a specific . /// /// Message public MibException(string message) : base(message) { } /// /// Creates a instance with a specific and an . /// /// Message /// Inner exception public MibException(string message, Exception inner) : base(message, inner) { } #if (!SILVERLIGHT) /// /// Creates a instance. /// /// Info /// Context private MibException(SerializationInfo info, StreamingContext context) : base(info, context) { if (info == null) { throw new ArgumentNullException("info"); } Symbol = (Symbol)info.GetValue("Symbol", typeof(Symbol)); } /// /// Gets object data. /// /// Info /// Context [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] public override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue("Symbol", Symbol); } #endif /// /// Creates a with a specific . /// /// Message /// Symbol /// public static MibException Create(string message, Symbol symbol) { if (symbol == null) { throw new ArgumentNullException("symbol"); } if (String.IsNullOrEmpty(message)) { message = "Unknown MIB Exception"; } message = String.Format( "{0} (file: \"{1}\"; row: {2}; column: {3})", message, symbol.File, symbol.Row + 1, symbol.Column + 1); MibException ex = new MibException(message) { Symbol = symbol }; return ex; } } }