Table of Contents

Struct Optional<T>

Namespace
DSharpPlus.Entities
Assembly
DSharpPlus.dll

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

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

Type Parameters

T

Type of the value.

Implements

Constructors

Optional(T)

Creates a new Optional<T> with specified value.

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.

GetHashCode()

Gets the hash code for this Optional<T>.

IfPresent<TTarget>(Func<T, TTarget>)

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

IsDefined(out T?)

Determines whether the optional has a value, and the value is non-null.

ToString()

Returns a string representation of this optional value.

Operators

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