Table of Contents

Struct Optional<T>

Namespace
DisCatSharp.Entities
Assembly
DisCatSharp.dll

Represents a wrapper which may or may not have a value.

[JsonConverter(typeof(OptionalJsonConverter))]
public readonly struct Optional<T> : IEquatable<Optional<T>>, IEquatable<T>, IOptional

Type Parameters

T

Type of the value.

Implements
Inherited Members

Constructors

Optional(T)

Creates a new Optional<T> with specified value.

Fields

None

Static empty Optional.

Properties

HasValue

Gets whether this Optional<T> has a value.

Value

Gets the value of this Optional<T>.

Methods

Equals(Optional<T>)

Checks whether this Optional<T> is equal to another Optional<T>.

Equals(object)

Checks whether this Optional<T> (or its value) are equal to another object.

Equals(T)

Checks whether the value of this Optional<T> is equal to specified object.

Expect(Exception)

Gets the Optional's value, or throws the provided exception if it's empty.

Expect(string)

Gets the Optional's value, or throws a standard exception with the provided string if it's empty.

GetHashCode()

Gets the hash code for this Optional<T>.

HasValueAnd(Predicate<T>)

Checks if this has a value and tests the predicate if it does.

MapOrNull<TOut>(Func<T, TOut>)

Maps to None for None, to

default
for
null
and to the mapped value otherwise./>
Map<TOut>(Func<T, TOut>)

Performs a mapping operation on the current Optional<T>, turning it into an Optional holding a TOut instance if the source optional contains a value; otherwise, returns an Optional<T> of that same type with no value.

ToString()

Returns a string representation of this optional value.

ValueOr(T)

Gets the value of the Optional<T> or a specified value, if the Optional<T> has no value.

ValueOrDefault()

Gets the value of the Optional<T> or the default value for T, if the Optional<T> has no value.

Operators

operator ==(Optional<T>, Optional<T>)
operator ==(Optional<T>, T)
explicit operator T(Optional<T>)
implicit operator Optional<T>(None)

Creates an empty optional.

implicit operator Optional<T>(T)
operator !=(Optional<T>, Optional<T>)
operator !=(Optional<T>, T)

Explicit Interface Implementations

IOptional.RawValue

Gets the raw value.