PutridParrot.Options/OptionalExtensions.cs
/// <summary>
/// If the Optional 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="optional"></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 Optional has no value then the exceptionFunc
is called to supply the Exception to be thrown
If the Optional has no value then the exceptionFunc is called to supply the Exception to be thrown
public static T OrException<T, TException>(this Optional<T> optional, Func<TException> exceptionFunc)
            where TException : Exception
        {
            if (exceptionFunc == null)
            {
                throw new ArgumentNullException(nameof(exceptionFunc));
            }
            if (optional.IsNone)
            {
                throw exceptionFunc();
            }
            return optional.Value;
        }
public static T OrException < T , TException > ( this Optional < T > optional , Func < TException > exceptionFunc ) where TException : Exception { if ( exceptionFunc == null ) { throw new ArgumentNullException ( nameof ( exceptionFunc ) ) ; } if ( optional . IsNone ) { throw exceptionFunc ( ) ; } return optional . Value ; }
If the Optional has no value then the exceptionFunc
is called to supply the Exception to be thrown
If the Optional has no value then the exceptionFunc is called to supply the Exception to be thrown
None
Optional<T>
this
<not_specific>
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
optional
<not_specific>
None
typeparam
None
typeparam
None