DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="5.3.1" />

.NET API 500,632 bytes

 Optional<T>

A container object which may or may not contain a value.
public static Optional<T> None { get; }

Represents optional container without value.

public bool HasValue { get; }

Indicates whether the value is present.

public bool IsNull { get; }

Indicates that the value is null.

public bool IsUndefined { get; }

Indicates that the value is undefined.

public T Value { get; }

If a value is present, returns the value, otherwise throw exception.

public T ValueOrDefault { get; }

If a value is present, returns the value, otherwise default value.

public T& modreq(System.Runtime.InteropServices.InAttribute) ValueRef { get; }

Obtains immutable reference to the value in the container.

public Optional(T value)

Constructs non-empty container.

public static bool IsValueDefined(T value)

Determines whether the object represents meaningful value.

public static Optional<T> op_BitwiseOr(ref Optional first, ref Optional second)

Returns non-empty container.

public static T op_BitwiseOr(ref Optional optional, T defaultValue)

Returns the value if present; otherwise return default value.

public static bool op_Equality(ref Optional first, ref Optional second)

Determines whether two containers store the same value.

public static Optional<T> op_ExclusiveOr(ref Optional first, ref Optional second)

Determines whether two containers are empty or have values.

public static T op_Explicit(ref Optional optional)

Extracts value stored in the Optional container.

public static bool op_False(ref Optional optional)

Checks whether the container has no value.

public static Optional<T> op_Implicit(T value)

Wraps value into Optional container.

public static bool op_Inequality(ref Optional first, ref Optional second)

Determines whether two containers store the different values.

public static bool op_True(ref Optional optional)

Checks whether the container has value.

public Optional<object> Box()

Boxes value encapsulated by this object.

public Optional<TResult> Convert<TResult>(Converter<T, TResult> mapper)

If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise returns None.

public Optional<TResult> Convert<TResult>(method mapper)

public Optional<TResult> Convert<TResult>(Converter<T, Optional<TResult>> mapper)

If a value is present, apply the provided mapping function to it, and if the result is non-null, return an Optional describing the result. Otherwise returns None.

public Optional<TResult> Convert<TResult>(method mapper)

public bool Equals(T other)

Determines whether this container stored the same value as the specified value.

public bool Equals(Optional<T> other)

Determines whether this container stores the same value as other.

public bool Equals(object other, IEqualityComparer comparer)

Performs equality check between stored value and the specified value using method Equals.

public int GetHashCode(IEqualityComparer comparer)

Computes hash code for the stored value using method GetHashCode.

public T& modreq(System.Runtime.InteropServices.InAttribute) GetReference<TException>() where TException : Exception

Obtains immutable reference to the value in the container.

public T& modreq(System.Runtime.InteropServices.InAttribute) GetReference(Func<Exception> exceptionFactory)

Obtains immutable reference to the value in the container.

public T& modreq(System.Runtime.InteropServices.InAttribute) GetReference(method exceptionFactory)

public Optional<T> If(Predicate<T> condition)

If a value is present, and the value matches the given predicate, return an Optional describing the value, otherwise return an empty Optional.

public Optional<T> If(method condition)

public T Or(T defaultValue)

Returns the value if present; otherwise return default value.

public T OrInvoke(Func<T> defaultFunc)

Returns the value if present; otherwise invoke delegate.

public T OrInvoke(method defaultFunc)

public T OrThrow<TException>() where TException : Exception

If a value is present, returns the value, otherwise throw exception.

public T OrThrow(Func<Exception> exceptionFactory)

If a value is present, returns the value, otherwise throw exception.

public T OrThrow(method exceptionFactory)

public bool TryGet(out T value)

Attempts to extract value from container if it is present.

public bool TryGet(out T value, out bool isNull)

Attempts to extract value from container if it is present.