Struct Optional<T>
Represents a wrapper which may or may not have a value.
Assembly: KSharpPlus.dll
Syntax
public readonly struct Optional<T> : IOptional
Type Parameters
Name |
Description |
T |
Type of the value.
|
Constructors
|
Improve this Doc
View Source
Optional(T)
Declaration
Parameters
Type |
Name |
Description |
T |
value |
Value of this option.
|
Properties
|
Improve this Doc
View Source
HasValue
Declaration
public readonly bool HasValue { get; }
Property Value
|
Improve this Doc
View Source
Value
Declaration
public readonly T Value { get; }
Property Value
Methods
|
Improve this Doc
View Source
Equals(T)
Checks whether the value of this Optional<T> is equal to specified object.
Declaration
public readonly bool Equals(T e)
Parameters
Type |
Name |
Description |
T |
e |
Object to compare to.
|
Returns
|
Improve this Doc
View Source
Equals(Optional<T>)
Declaration
public readonly bool Equals(Optional<T> e)
Parameters
Returns
|
Improve this Doc
View Source
Equals(Object)
Checks whether this Optional<T> (or its value) are equal to another object.
Declaration
public override readonly bool Equals(object obj)
Parameters
Type |
Name |
Description |
Object |
obj |
Object to compare to.
|
Returns
Overrides
|
Improve this Doc
View Source
GetHashCode()
Declaration
public override readonly int GetHashCode()
Returns
Overrides
|
Improve this Doc
View Source
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.
Declaration
public readonly Optional<TTarget> IfPresent<TTarget>(Func<T, TTarget> mapper)
Parameters
Type |
Name |
Description |
Func<T, TTarget> |
mapper |
The mapping function to apply on the current value if it exists
|
Returns
Type Parameters
Name |
Description |
TTarget |
The type of the target value returned by mapper
|
|
Improve this Doc
View Source
IsDefined(out T)
Determines whether the optional has a value, and the value is non-null.
Declaration
public readonly bool IsDefined(out T value)
Parameters
Type |
Name |
Description |
T |
value |
The value contained within the optional.
|
Returns
Type |
Description |
Boolean |
True if the value is set, and is not null, otherwise false.
|
|
Improve this Doc
View Source
ToString()
Returns a string representation of this optional value.
Declaration
public override readonly string ToString()
Returns
Type |
Description |
String |
String representation of this optional value.
|
Overrides
Operators
|
Improve this Doc
View Source
Equality(Optional<T>, T)
Declaration
public static bool operator ==(Optional<T> opt, T t)
Parameters
Type |
Name |
Description |
Optional<T> |
opt |
|
T |
t |
|
Returns
|
Improve this Doc
View Source
Equality(Optional<T>, Optional<T>)
Declaration
public static bool operator ==(Optional<T> opt1, Optional<T> opt2)
Parameters
Returns
|
Improve this Doc
View Source
Explicit(Optional<T> to T)
Declaration
public static explicit operator T(Optional<T> opt)
Parameters
Returns
|
Improve this Doc
View Source
Implicit(T to Optional<T>)
Declaration
public static implicit operator Optional<T>(T val)
Parameters
Type |
Name |
Description |
T |
val |
|
Returns
|
Improve this Doc
View Source
Inequality(Optional<T>, T)
Declaration
public static bool operator !=(Optional<T> opt, T t)
Parameters
Type |
Name |
Description |
Optional<T> |
opt |
|
T |
t |
|
Returns
|
Improve this Doc
View Source
Inequality(Optional<T>, Optional<T>)
Declaration
public static bool operator !=(Optional<T> opt1, Optional<T> opt2)
Parameters
Returns
Explicit Interface Implementations
|
Improve this Doc
View Source
IOptional.RawValue
Declaration
readonly object IOptional.RawValue { get; }
Returns
Implements
IEquatable<>
IEquatable<>