test/Qowaiv.CodeGenerator.UnitTests/Guard.cs
/// <summary>Throws an <see cref="ArgumentOutOfRangeException"/> if the parameter not in not a defined value of the enum, otherwise the parameter is passed.</summary>
/// <typeparam name="T">The type to guard; must be a structure (enum).</typeparam>
/// <param name="parameter">The parameter to guard.</param>
/// <param name="paramName">The name of the parameter.</param>
/// <remarks>
/// That <typeparamref name="T"/> is an enum is implicitly guard by <see cref="Enum.IsDefined(Type, object)"/>.
/// </remarks>
Throws an  if the parameter not in not a defined value of the enum, otherwise the parameter is passed.
Throws an if the parameter not in not a defined value of the enum otherwise the parameter is passed .
public static T DefinedEnum<T>(T parameter, string paramName) where T : struct
        {
            if (Enum.IsDefined(typeof(T), parameter))
            {
                return parameter;
            }
            throw new ArgumentOutOfRangeException(paramName, string.Format(CultureInfo.CurrentCulture, Messages.ArgumentOutOfRangeException_DefinedEnum, parameter, typeof(T)));
        }
public static T DefinedEnum < T > ( T parameter , string paramName ) where T : struct { if ( Enum . IsDefined ( typeof ( T ) , parameter ) ) { return parameter ; } throw new ArgumentOutOfRangeException ( paramName , string . Format ( CultureInfo . CurrentCulture , Messages . ArgumentOutOfRangeException_DefinedEnum , parameter , typeof ( T ) ) ) ; }
Throws an  if the parameter not in not a defined value of the enum, otherwise the parameter is passed.
Throws an if the parameter not in not a defined value of the enum otherwise the parameter is passed .
parameter
T
The parameter to guard.
The parameter to guard .
paramName
string
The name of the parameter.
The name of the parameter .
typeparam
The type to guard; must be a structure (enum).
The type to guard ; must be a structure ( enum ) .
remarks
That  is an enum is implicitly guard by .
That is an enum is implicitly guard by .