-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee78423
commit 9ca217e
Showing
7 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// Conversion Exception. | ||
/// </summary> | ||
/// <seealso cref="System.Exception" /> | ||
/// <remarks>Thrown when a conversion to a specified type fails</remarks> | ||
public class ConversionException : Exception | ||
{ | ||
/// <summary> | ||
/// Gets the value. | ||
/// </summary> | ||
/// <value>The value.</value> | ||
public string Value { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the type of the convert. | ||
/// </summary> | ||
/// <value>The type of the convert.</value> | ||
public Type ConvertType { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConversionException" /> class. | ||
/// </summary> | ||
/// <param name="value">The value.</param> | ||
/// <param name="message">The message.</param> | ||
public ConversionException(string value, string message) | ||
: this(value, message, null) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConversionException" /> class. | ||
/// </summary> | ||
/// <param name="value">The value.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="type">The type.</param> | ||
public ConversionException(string value, string message, Type type) | ||
: base(message) | ||
{ | ||
Value = value; | ||
ConvertType = type; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// EnumTypeException. | ||
/// </summary> | ||
/// <seealso cref="System.Exception" /> | ||
public class EnumTypeException : Exception | ||
{ | ||
/// <summary> | ||
/// The message template | ||
/// </summary> | ||
private const string MessageTemplate = "{0} is not an enumeration type"; | ||
|
||
/// <summary> | ||
/// The type the exception was thrown for | ||
/// </summary> | ||
/// <value>The type.</value> | ||
public Type Type { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EnumTypeException" /> class. | ||
/// </summary> | ||
/// <param name="type">The type.</param> | ||
/// <remarks>Uses the default message template</remarks> | ||
public EnumTypeException(Type type) | ||
: this(type, MessageTemplate) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EnumTypeException" /> class. | ||
/// </summary> | ||
/// <param name="type">The type.</param> | ||
/// <param name="messageTemplate">The message template.</param> | ||
public EnumTypeException(Type type, string messageTemplate) | ||
: base(string.Format(messageTemplate, type.Name)) | ||
{ | ||
Type = type; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// Class EnumValueException. | ||
/// </summary> | ||
/// <seealso cref="System.Exception" /> | ||
public class EnumValueException<T> : Exception | ||
{ | ||
/// <summary> | ||
/// The message template | ||
/// </summary> | ||
private const string MessageTemplate = "{0} is not a valid {1} value"; | ||
|
||
/// <summary> | ||
/// Gets the type. | ||
/// </summary> | ||
/// <value>The type.</value> | ||
public Type Type { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets the value. | ||
/// </summary> | ||
/// <value>The value.</value> | ||
public T Value { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EnumValueException{T}"/> class. | ||
/// </summary> | ||
/// <param name="value">The value.</param> | ||
public EnumValueException(T value) | ||
: this(value, MessageTemplate) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EnumValueException{T}"/> class. | ||
/// </summary> | ||
/// <param name="value">The value.</param> | ||
/// <param name="messageTemplate">The message template.</param> | ||
public EnumValueException(T value, string messageTemplate) | ||
: base(string.Format(messageTemplate, value, typeof(T).Name)) | ||
{ | ||
Type = typeof(T); | ||
Value = value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// Exception Extensions. | ||
/// </summary> | ||
public static class ExceptionExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the list of messages from an Exception and inner exceptions | ||
/// </summary> | ||
/// <param name="ex">The ex.</param> | ||
/// <returns>IList<System.String>.</returns> | ||
/// <remarks>Also available as an extension method</remarks> | ||
public static IList<string> GetMessageList(this Exception ex) | ||
{ | ||
var list = new List<string>(); | ||
|
||
while (ex != null) | ||
{ | ||
list.Add(ex.Message); | ||
|
||
ex = ex.InnerException; | ||
} | ||
|
||
return list; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the list of messages from an Exception and inner exceptions | ||
/// </summary> | ||
/// <param name="ex">The ex.</param> | ||
/// <returns>IList<System.String>.</returns> | ||
/// <remarks>Also available as an extension method</remarks> | ||
public static IList<Exception> GetExceptionList(this Exception ex) | ||
{ | ||
var list = new List<Exception>(); | ||
|
||
while (ex != null) | ||
{ | ||
list.Add(ex); | ||
|
||
ex = ex.InnerException; | ||
} | ||
|
||
return list; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// An exception for idenifying issues with expected parameters | ||
/// </summary> | ||
/// <seealso cref="System.Exception" /> | ||
public class ParameterException : Exception | ||
{ | ||
/// <summary> | ||
/// The Parameter Name | ||
/// </summary> | ||
/// <value>The name of the parameter.</value> | ||
public string ParamName { get; private set; } | ||
|
||
/// <summary> | ||
/// The value specified for the Parameter | ||
/// </summary> | ||
/// <value>The parameter value.</value> | ||
public object ParamValue { get; private set; } | ||
|
||
/// <summary> | ||
/// Create a ParameterException with a parameter name and a message | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="message">The message.</param> | ||
public ParameterException(string paramName, string message) | ||
: base(message) | ||
{ | ||
ParamName = paramName; | ||
} | ||
|
||
/// <summary> | ||
/// Create a ParameterException with a parameter name and value, and a message | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="paramValue">The parameter value.</param> | ||
/// <param name="message">The message.</param> | ||
public ParameterException(string paramName, object paramValue, string message) | ||
: base(message) | ||
{ | ||
ParamName = paramName; | ||
ParamValue = paramValue; | ||
} | ||
|
||
/// <summary> | ||
/// Create a ParameterException with a parameter name, message and inner Exception | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="innerException">The inner exception.</param> | ||
public ParameterException(string paramName, string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
ParamName = paramName; | ||
} | ||
|
||
/// <summary> | ||
/// Create a ParameterException with a parameter name and value, message and inner Exception | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="paramValue">The parameter value.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="innerException">The inner exception.</param> | ||
public ParameterException(string paramName, object paramValue, string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
ParamName = paramName; | ||
ParamValue = paramValue; | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/DNX.Extensions/Exceptions/ParameterInvalidException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// An exception for idenifying an invalid value issue with expected parameters | ||
/// </summary> | ||
/// <seealso cref="ParameterException" /> | ||
public class ParameterInvalidException : ParameterException | ||
{ | ||
/// <summary> | ||
/// Create a ParameterInvalidException with a parameter name and a message | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="message">The message.</param> | ||
public ParameterInvalidException(string paramName, string message) | ||
: base(paramName, message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Create a ParameterInvalidException with a parameter name and value, and a message | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="paramValue">The parameter value.</param> | ||
/// <param name="message">The message.</param> | ||
public ParameterInvalidException(string paramName, object paramValue, string message) | ||
: base(paramName, paramValue, message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Create a ParameterInvalidException with a parameter name, message and inner Exception | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="innerException">The inner exception.</param> | ||
public ParameterInvalidException(string paramName, string message, Exception innerException) | ||
: base(paramName, message, innerException) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Create a ParameterInvalidException with a parameter name and value, message and inner Exception | ||
/// </summary> | ||
/// <param name="paramName">Name of the parameter.</param> | ||
/// <param name="paramValue">The parameter value.</param> | ||
/// <param name="message">The message.</param> | ||
/// <param name="innerException">The inner exception.</param> | ||
public ParameterInvalidException(string paramName, object paramValue, string message, Exception innerException) | ||
: base(paramName, paramValue, message, innerException) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace DNX.Extensions.Exceptions | ||
{ | ||
/// <summary> | ||
/// Class ReadOnlyListException. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <seealso cref="System.Exception" /> | ||
public class ReadOnlyListException<T> : Exception | ||
{ | ||
/// <summary> | ||
/// Gets the list. | ||
/// </summary> | ||
/// <value>The list.</value> | ||
public IList<T> List { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ReadOnlyListException{T}" /> class. | ||
/// </summary> | ||
/// <param name="list">The list.</param> | ||
public ReadOnlyListException(IList<T> list) | ||
{ | ||
List = list; | ||
} | ||
} | ||
} |