This repository has been archived by the owner on Jun 11, 2021. It is now read-only.
forked from dotnet/dotNext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenericArgumentException.cs
46 lines (43 loc) · 1.67 KB
/
GenericArgumentException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
namespace DotNext
{
/// <summary>
/// The exception that is thrown when one of the generic arguments
/// provided to a type is not valid.
/// </summary>
public class GenericArgumentException : ArgumentException
{
/// <summary>
/// Initializes a new exception.
/// </summary>
/// <param name="genericParam">Incorrect actual generic argument.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="paramName">The name of generic parameter.</param>
public GenericArgumentException(Type genericParam, string message, string? paramName = null)
: base(message, string.IsNullOrEmpty(paramName) ? genericParam.FullName : paramName)
{
Argument = genericParam;
}
/// <summary>
/// Generic argument.
/// </summary>
public Type Argument { get; }
}
/// <summary>
/// The exception that is thrown when one of the generic arguments
/// provided to a type is not valid.
/// </summary>
/// <typeparam name="T">Captured generic argument treated as invalid.</typeparam>
public class GenericArgumentException<T> : GenericArgumentException
{
/// <summary>
/// Initializes a new exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="paramName">The name of generic parameter.</param>
public GenericArgumentException(string message, string? paramName = null)
: base(typeof(T), message, paramName)
{
}
}
}