Show / Hide Table of Contents
  • MaybeSharp
    • Maybe<T>
      • As
      • Bind
      • Cast
      • CompareTo
      • Equality
      • Equals
      • Explicit
      • GetHashCode
      • GreaterThan
      • GreaterThanOrEqual
      • HasValue
      • Implicit
      • Inequality
      • IsEmpty
      • LessThan
      • LessThanOrEqual
      • Maybe
      • Nothing
      • ToString
      • Value
  • MaybeSharp.Extensions
    • MaybeDictionaryExtensions
      • TryGetValue
    • MaybeExtensions
      • Coalesce
      • Or
      • Select
      • SelectMany
      • SelectNonempty
      • ToNullable
      • ValueOr
      • ValueOrException
      • WhenNothing
      • WhenSomething
      • Where
    • MaybeStringExtensions
      • TryParseBoolean
      • TryParseByte
      • TryParseChar
      • TryParseDateTime
      • TryParseDateTimeOffset
      • TryParseDecimal
      • TryParseDouble
      • TryParseInt
      • TryParseInt16
      • TryParseInt64
      • TryParseSingle
    • NullableExtensions
      • ToMaybe

Method ValueOrException

ValueOrException<T>(Maybe<T>, Exception)

Returns the value of source if it is not empty, otherwise throws the provided exception.

Declaration
public static T ValueOrException<T>(this Maybe<T> source, Exception exception)
Parameters
Type Name Description
Maybe<T> source

The Mabye{T} instance whose value is returned if it is not empty.

Exception exception

The exception to throw if source is empty. If null, an System.InvalidOperationException is thrown.

Returns
Type Description
T

The value of source.

Type Parameters
Name Description
T

The sub-type of the Maybe{T} instances.

ValueOrException<T>(Maybe<T>, Func<Exception>)

Returns the value of source if it is not empty, otherwise throws an exception created from the function provided.

Declaration
public static T ValueOrException<T>(this Maybe<T> source, Func<Exception> exceptionFactory)
Parameters
Type Name Description
Maybe<T> source

The Mabye{T} instance whose value is returned if it is not empty.

Func<Exception> exceptionFactory

A function that builds the exception to be thrown if source is empty. If the function is null or returns null, a System.InvalidOperationException is thrown.

Returns
Type Description
T

The value of source.

Type Parameters
Name Description
T

The sub-type of the Maybe{T} instances.

Back to top Copyright (c) 2017 Troy Willmot