Class Optional<T>
Represents a specifically-typed resource that includes an 'Empty' state to discourage referencing a null
value.
Namespace: Unity.DigitalTwins.Live.Sdk.Utilities
Assembly: solution.dll
Syntax
[Serializable]
public class Optional<T> : Optional
Type Parameters
Name | Description |
---|---|
T | The type of the contained value. |
Constructors
Optional()
Creates an instance of Optional
in an Empty
state with a default
value.
Declaration
public Optional()
Optional(T)
Creates an instance of Optional
and assigns the type
value
. Construction with anull
value
results in an 'Empty' state.Declaration
public Optional(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The resource this class represents. |
Methods
Equals(Object)
Compares the contained value to another object
.
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
Object | other | The |
Returns
Type | Description |
---|---|
Boolean | True if other isOptional and matches the contained value.
|
Overrides
Get()
Retrieves the contained value.
Declaration
public T Get()
Returns
Type | Description |
---|---|
T | The contained value. |
GetHashCode()
Retrieves a hash code representing an Optional
value.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | A hash code made up of the contained value and its |
Overrides
GetOrDefault()
Retrieves the contained value if it's assigned. Otherwise uses the default
value.
Declaration
public T GetOrDefault()
Returns
Type | Description |
---|---|
T | The contained value if it's not |
GetOrElse(T)
Retrieves the contained value if it's assigned. Otherwise uses the
other
value.Declaration
public T GetOrElse(T other)
Parameters
Type | Name | Description |
---|---|---|
T | other | The alternative value. |
Returns
Type | Description |
---|---|
T | The contained value if it's not other value. |
IsEmpty()
Queries the state of the contained value.
Declaration
public bool IsEmpty()
Returns
Type | Description |
---|---|
Boolean | True if the value is |
IsPresent()
Queries the state of the contained value.
Declaration
public bool IsPresent()
Returns
Type | Description |
---|---|
Boolean | True if the value in not |
ToString()
Retrieves the contained value as a string
.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The contained value as a |