using System; using System.Runtime.Serialization; namespace Swan { /// /// The exception that is thrown when a conversion from a string to a /// specified type fails. /// /// [Serializable] public class StringConversionException : Exception { /// /// Initializes a new instance of the class. /// public StringConversionException() { } /// /// Initializes a new instance of the class. /// /// The error message that explains the reason for the exception. public StringConversionException(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 if no inner exception is specified. public StringConversionException(string message, Exception innerException) : base(message, innerException) { } /// /// Initializes a new instance of the class. /// /// The desired resulting type of the attempted conversion. public StringConversionException(Type type) : base(BuildStandardMessageForType(type)) { } /// /// Initializes a new instance of the class. /// /// The desired resulting type of the attempted conversion. /// The exception that is the cause of the current exception, /// or if no inner exception is specified. public StringConversionException(Type type, Exception innerException) : base(BuildStandardMessageForType(type), innerException) { } /// /// 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. protected StringConversionException(SerializationInfo info, StreamingContext context) : base(info, context) { } private static string BuildStandardMessageForType(Type type) => $"Cannot convert a string to an instance of {type.FullName}"; } }