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
-
IEquatable<Optional<T>>IEquatable<T>
- Inherited Members
Constructors
- Optional(T)
Creates a new Optional<T> with specified value.
Fields
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>)
fordefault
and to the mapped value otherwise./>null
- 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
- implicit operator Optional<T>(None)
Creates an empty optional.
Explicit Interface Implementations
- IOptional.RawValue
Gets the raw value.