using System; using System.Runtime.Serialization; namespace Umbraco.Core.Exceptions { /// /// /// /// /// [Serializable] public class DataOperationException : Exception where T : Enum { /// /// Gets the operation. /// /// /// The operation. /// /// /// This object should be serializable to prevent a to be thrown. /// public T Operation { get; private set; } /// /// Initializes a new instance of the class. /// public DataOperationException() { } /// /// Initializes a new instance of the class. /// /// The message that describes the error. public DataOperationException(string message) : base(message) { } /// /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. /// The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. public DataOperationException(string message, Exception innerException) : base(message, innerException) { } /// /// Initializes a new instance of the class. /// /// The operation. public DataOperationException(T operation) : this(operation, "Data operation exception: " + operation) { } /// /// Initializes a new instance of the class. /// /// The operation. /// The message. public DataOperationException(T operation, string message) : base(message) { Operation = operation; } /// /// Initializes a new instance of the class. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// info protected DataOperationException(SerializationInfo info, StreamingContext context) : base(info, context) { Operation = (T)Enum.Parse(typeof(T), info.GetString(nameof(Operation))); } /// /// When overridden in a derived class, sets the with information about the exception. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. /// info public override void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException(nameof(info)); } info.AddValue(nameof(Operation), Enum.GetName(typeof(T), Operation)); base.GetObjectData(info, context); } } }