test/Qowaiv.CodeGenerator.UnitTests/Guard.cs
/// <summary>
/// Guards that the parameter is an instance of T, otherwise throws an argument (null) exception.
/// It only makes sense to use this function if the original type of the <paramref name="parameter"/>
/// is <see cref="object"/>, otherwise one should simply use <see cref="NotNull{T}(T, string)"/>.
/// </summary>
/// <typeparam name="T">The type to guard</typeparam>
/// <param name="parameter">The parameter to guard.</param>
/// <param name="paramName">The name of the parameter.</param>
Guards that the parameter is an instance of T, otherwise throws an argument (null) exception.
It only makes sense to use this function if the original type of the
is , otherwise one should simply use .
Guards that the parameter is an instance of T otherwise throws an argument ( null ) exception . It only makes sense to use this function if the original type of the is otherwise one should simply use .
[DebuggerStepThrough]
#pragma warning disable S4018 
        public static T IsInstanceOf<T>(object parameter, string paramName)
#pragma warning restore S4018 
        {
            NotNull(parameter, paramName);
            if (!(parameter is T))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Messages.ArgumentException_NotAnInstanceOf, typeof(T)), paramName);
            }
            return (T)parameter;
        }
[ DebuggerStepThrough ] pragma warning disable S4018 public static T IsInstanceOf < T > ( object parameter , string paramName ) pragma warning restore S4018 { NotNull ( parameter , paramName ) ; if ( ! ( parameter is T ) ) { throw new ArgumentException ( string . Format ( CultureInfo . CurrentCulture , Messages . ArgumentException_NotAnInstanceOf , typeof ( T ) ) , paramName ) ; } return ( T ) parameter ; }
Guards that the parameter is an instance of T, otherwise throws an argument (null) exception.
Guards that the parameter is an instance of T otherwise throws an argument ( null ) exception .
// Generic methods should provide type parameters, but here it provides casting. // Generic methods should provide type parameters
parameter
object
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
The type to guard