TypeArgumentOutOfRangeException Class
Definition
- Namespace
- Cuemon
- Assemblies
- Cuemon.Kernel.dll
The exception that is thrown when the value of an type argument is outside the allowable range of values as defined by the invoked method.
public class TypeArgumentOutOfRangeException : ArgumentOutOfRangeException, ISerializable
- Inheritance
-
TypeArgumentOutOfRangeException
- Implements
- Inherited Members
Examples
The following example demonstrates how to throw a
using System;
using Cuemon;
namespace Contoso.Logging;
public sealed class TypeArgumentOutOfRangeExceptionExample
{
public static void Run()
{
LogLevel parsed = ParseEnum<LogLevel>("Warning");
Console.WriteLine(parsed);
try
{
ParseEnum<int>("1");
}
catch (TypeArgumentOutOfRangeException ex)
{
Console.WriteLine($"{ex.ParamName}: {ex.ActualValue}");
}
}
private static TEnum ParseEnum<TEnum>(string text)
where TEnum : struct
{
if (!typeof(TEnum).IsEnum)
{
throw new TypeArgumentOutOfRangeException(
nameof(TEnum),
typeof(TEnum),
"Type arguments must be enum types.");
}
return (TEnum)Enum.Parse(typeof(TEnum), text, ignoreCase: true);
}
private enum LogLevel
{
Debug,
Information,
Warning,
Error
}
}
Constructors
| Name | Description |
|---|---|
| TypeArgumentOutOfRangeException() | Initializes a new instance of the TypeArgumentOutOfRangeException class. |
| TypeArgumentOutOfRangeException(string) | Initializes a new instance of the TypeArgumentOutOfRangeException class. |
| TypeArgumentOutOfRangeException(string, Exception) | Initializes a new instance of the TypeArgumentOutOfRangeException class. |
| TypeArgumentOutOfRangeException(string, object, string) | Initializes a new instance of the TypeArgumentOutOfRangeException class. |
| TypeArgumentOutOfRangeException(string, string) | Initializes a new instance of the TypeArgumentOutOfRangeException class. |