PutridParrot.Options/OptionExtensions.cs
/// <summary>
/// If the Option has no value then the exceptionFunc
/// is called to supply the Exception to be thrown
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TException"></typeparam>
/// <param name="option"></param>
/// <param name="exceptionFunc">The function that returns an instance of the exception
/// which will be thrown. Must not be null</param>
/// <returns></returns>
If the Option has no value then the exceptionFunc
is called to supply the Exception to be thrown
If the Option has no value then the exceptionFunc is called to supply the Exception to be thrown
public static T OrException<T, TException>(this Option<T> option, Func<TException> exceptionFunc)
            where TException : Exception
        {
            if (exceptionFunc == null)
            {
                throw new ArgumentNullException(nameof(exceptionFunc));
            }
            switch (option)
            {
                case Some<T> some:
                    return some.Value;
                default:
                    throw exceptionFunc();
            }
        }
public static T OrException < T , TException > ( this Option < T > option , Func < TException > exceptionFunc ) where TException : Exception { if ( exceptionFunc == null ) { throw new ArgumentNullException ( nameof ( exceptionFunc ) ) ; } switch ( option ) { case Some < T > some : return some . Value ; default : throw exceptionFunc ( ) ; } }
If the Option has no value then the exceptionFunc
is called to supply the Exception to be thrown
If the Option has no value then the exceptionFunc is called to supply the Exception to be thrown
None
Option<T>
this
exceptionFunc
Func<TException>
The function that returns an instance of the exception
which will be thrown. Must not be null
The function that returns an instance of the exception which will be thrown . Must not be null
option
None
typeparam
None
typeparam
None