Optional<T> Struct
Definition
An optional typed value.
public struct Optional<T>
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 Avalonia.Data.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 Avalonia.Data.Optional<T> constructor or use an implicit
conversion from
T - For an missing value, use Avalonia.Data.Optional<T>.Empty or simply
default
Constructors
| Name | Description |
|---|---|
| Optional<T> | Initializes a new instance of the Avalonia.Data.Optional<T> struct with value. |
Optional<T> Constructor
Initializes a new instance of the Avalonia.Data.Optional<T> struct with value.
public Optional<T>(T value)
Parameters
value T
The value.
Methods
| Name | Description |
|---|---|
| Equals (2 overloads) | No summary available. |
| GetHashCode | No summary available. |
| GetValueOrDefault (3 overloads) | Gets the value if present, otherwise the default value. |
| ToObject | Casts the value (if any) to an object. |
| ToString | No summary available. |
Equals overloads
Equals Method
public bool Equals(Avalonia.Data.Optional<T><T> other)
Parameters
other Avalonia.Data.Optional<T><T>
Returns
bool
Equals Method
public bool Equals(object obj)
Parameters
obj object
Returns
bool
GetHashCode Method
public int GetHashCode()
Returns
int
GetValueOrDefault overloads
GetValueOrDefault Method
Gets the value if present, otherwise the default value.
public TResult GetValueOrDefault<TResult>()
Returns
T
The value.
GetValueOrDefault Method
Gets the value if present, otherwise a default value.
public T GetValueOrDefault(T defaultValue)
Parameters
defaultValue T
The default value.
Returns
T
The value.
GetValueOrDefault Method
public TResult GetValueOrDefault<TResult>(TResult defaultValue)
Parameters
defaultValue TResult
Type Parameters
TResult
Returns
TResult
ToObject Method
Casts the value (if any) to an object.
public Avalonia.Data.Optional<T><object> ToObject()
Returns
Avalonia.Data.Optional<T><object>
The cast optional value.
ToString Method
public string ToString()
Returns
string
Properties
| Name | Description |
|---|---|
| Empty | Returns an Avalonia.Data.Optional<T> without a value. |
| HasValue | Gets a value indicating whether a value is present. |
| Value | Gets the value. |
Empty Property
Returns an Avalonia.Data.Optional<T> without a value.
public Avalonia.Data.Optional<T><T> Empty { get; set; }
HasValue Property
Gets a value indicating whether a value is present.
public bool HasValue { get; set; }
Value Property
Gets the value.
public T Value { get; set; }