Search Results for

    Show / Hide Table of Contents

    Struct Optional<T>

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

    Implements
    IEquatable<Optional<T>>
    IEquatable<T>
    IOptional
    Inherited Members
    Object.Equals(Object, Object)
    Object.GetType()
    Object.ReferenceEquals(Object, Object)
    Namespace: KSharpPlus.Entities
    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)

    Creates a new Optional<T> with specified value.

    Declaration
    public Optional(T value)
    Parameters
    Type Name Description
    T value

    Value of this option.

    Properties

    | Improve this Doc View Source

    HasValue

    Gets whether this Optional<T> has a value.

    Declaration
    public readonly bool HasValue { get; }
    Property Value
    Type Description
    Boolean
    | Improve this Doc View Source

    Value

    Gets the value of this Optional<T>.

    Declaration
    public readonly T Value { get; }
    Property Value
    Type Description
    T

    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
    Type Description
    Boolean

    Whether the object is equal to the value of this Optional<T>.

    | Improve this Doc View Source

    Equals(Optional<T>)

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

    Declaration
    public readonly bool Equals(Optional<T> e)
    Parameters
    Type Name Description
    Optional<T> e

    Optional<T> to compare to.

    Returns
    Type Description
    Boolean

    Whether the Optional<T> is equal to this Optional<T>.

    | 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
    Type Description
    Boolean

    Whether the object is equal to this Optional<T> or its value.

    Overrides
    ValueType.Equals(Object)
    | Improve this Doc View Source

    GetHashCode()

    Gets the hash code for this Optional<T>.

    Declaration
    public override readonly int GetHashCode()
    Returns
    Type Description
    Int32

    The hash code for this Optional<T>.

    Overrides
    ValueType.GetHashCode()
    | 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 Description
    Optional<TTarget>

    An Optional<T> containing a value denoted by calling mapper if the current Optional<T> contains a value; otherwise, an empty Optional<T> of the target type.

    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
    ValueType.ToString()

    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
    Type Description
    Boolean
    | Improve this Doc View Source

    Equality(Optional<T>, Optional<T>)

    Declaration
    public static bool operator ==(Optional<T> opt1, Optional<T> opt2)
    Parameters
    Type Name Description
    Optional<T> opt1
    Optional<T> opt2
    Returns
    Type Description
    Boolean
    | Improve this Doc View Source

    Explicit(Optional<T> to T)

    Declaration
    public static explicit operator T(Optional<T> opt)
    Parameters
    Type Name Description
    Optional<T> opt
    Returns
    Type Description
    T
    | 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
    Type Description
    Optional<T>
    | 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
    Type Description
    Boolean
    | Improve this Doc View Source

    Inequality(Optional<T>, Optional<T>)

    Declaration
    public static bool operator !=(Optional<T> opt1, Optional<T> opt2)
    Parameters
    Type Name Description
    Optional<T> opt1
    Optional<T> opt2
    Returns
    Type Description
    Boolean

    Explicit Interface Implementations

    | Improve this Doc View Source

    IOptional.RawValue

    Declaration
    readonly object IOptional.RawValue { get; }
    Returns
    Type Description
    Object

    Implements

    IEquatable<>
    IEquatable<>
    IOptional
    • Improve this Doc
    • View Source
    In This Article
    Back to top © 2023 KSharpPlus Contributors