Optional<T> Struct

Summary

An optional typed value.
Namespace
Avalonia.Data
Interfaces
Base Types
  • object
  • ValueType
graph BT Type-->Base0["ValueType"] Base0-->Base1["object"] Type-.->Interface0["IEquatable<Optional<T>>"] Type["Optional<T>"] class Type type-node

Syntax

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

Remarks

This struct is similar to System.Nullable`1 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`

Type Parameters

Name Description
T The value type.

Constructors

Name Summary
Optional(T) Initializes a new instance of the Optional<T> struct with value.

Properties

Name Value Summary
Empty Optional<T>
Returns an Optional<T> without a value.
static
HasValue bool
Gets a value indicating whether a value is present.
Value T
Gets the value.

Methods

Name Value Summary
Equals(object?) bool
Equals(Optional<T>) bool
GetHashCode() int
GetValueOrDefault() T
Gets the value if present, otherwise the default value.
GetValueOrDefault(T) T
Gets the value if present, otherwise a default value.
GetValueOrDefault<TResult>() TResult
Gets the value if present, otherwise the default value.
GetValueOrDefault<TResult>(TResult) TResult
Gets the value if present, otherwise a default value.
ToObject() Optional<object>
Casts the value (if any) to an object.
ToString() string

Operators

Name Value Summary
implicit operator Optional<T>(T) Optional<T>
operator !=(Optional<T>, Optional<T>) bool
operator ==(Optional<T>, Optional<T>) bool