OptionalT Structure

An optional typed value.

Definition

Namespace: Avalonia.Data
Assembly: Avalonia.Base (in Avalonia.Base.dll) Version: 11.3.999
public readonly struct Optional<T> : IEquatable<Optional<T>>
Inheritance
Object    ValueType    OptionalT
Implements
IEquatableOptionalT

Type Parameters

T
The value type.

Remarks

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

Properties

Empty Returns an OptionalT without a value.
HasValue Gets a value indicating whether a value is present.
Value Gets the value.

Methods

Equals(Object)Indicates whether this instance and a specified object are equal.
(Overrides ValueTypeEquals(Object))
Equals(OptionalT)Indicates whether the current object is equal to another object of the same type.
GetHashCodeReturns the hash code for this instance.
(Overrides ValueTypeGetHashCode)
GetTypeGets 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.
GetValueOrDefaultTResult Gets the value if present, otherwise the default value.
GetValueOrDefaultTResult(TResult) Gets the value if present, otherwise a default value.
ToObject Casts the value (if any) to an Object.
ToStringReturns the fully qualified type name of this instance.
(Overrides ValueTypeToString)

Operators

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

See Also