Skip to main content

Optional<T> Structure

An optional typed value.

Definition

Namespace: Avalonia.Data
Assembly: Avalonia.Base (in Avalonia.Base.dll)

public readonly struct Optional<T> : IEquatable<Optional<T>>

View Source
InheritanceObjectValueType → Optional(T)
ImplementsIEquatable(Optional(T))

Type Parameters

The value type.

Remarks

This struct is similar to Nullable(T) except it also accepts reference types: note that null is a valid value for reference types. It is also similar to BindingValue(T) but has only two states: "value present" and "value missing". To create a new optional value you can: - For a simple value, call the Optional(T) constructor or use an implicit conversion from T - For an missing value, use Empty or simply default

Constructors

Optional(T)(T)Initializes a new instance of the Optional(T) struct with value.

Properties

EmptyReturns an Optional(T) without a value.
HasValueGets a value indicating whether a value is present.
ValueGets the value.

Methods

Equals(Object)Indicates whether this instance and a specified object are equal.
(Overrides ValueType.Equals(Object))
Equals(Optional(T))Indicates whether the current object is equal to another object of the same type.
GetHashCode()Returns the hash code for this instance.
(Overrides ValueType.GetHashCode())
GetType()Gets the Type of the current instance.
(Inherited from Object)
GetValueOrDefault()Gets the value if present, otherwise the default value.
GetValueOrDefault(T)Gets the value if present, otherwise a default value.
GetValueOrDefault(TResult)()Gets the value if present, otherwise the default value.
GetValueOrDefault(TResult)(TResult)Gets the value if present, otherwise a default value.
ToObject()Casts the value (if any) to an Object.
ToString()Returns the fully qualified type name of this instance.
(Overrides ValueType.ToString())

Operators

Equality(Optional(T), Optional(T))Compares two Optional(T)s for equality.
Implicit(T to Optional(T))Creates an Optional(T) from an instance of the underlying value type.
Inequality(Optional(T), Optional(T))Compares two Optional(T)s for inequality.

See Also

Reference

Avalonia.Data Namespace