Struct Optional<T>
- Namespace
- DotTiled
- Assembly
- DotTiled.dll
Represents a value that may or may not be present.
public readonly struct Optional<T>
Type Parameters
TThe type of the optionally present value.
- Inherited Members
Constructors
Optional(T)
Constructs an Optional<T> with a meaningful value.
public Optional(T value)
Parameters
valueT
Properties
HasValue
public bool HasValue { get; }
Property Value
Value
public T Value { get; }
Property Value
Remarks
Methods
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetValueOr(T)
Returns the value of the current Optional<T> object if it has been set; otherwise, returns the specified default value.
public T GetValueOr(T defaultValue)
Parameters
defaultValueTThe value to be returned if the current Optional<T> object has no value.
Returns
- T
GetValueOrOptional(Optional<T>)
Returns the current Optional<T> object if it has a value; otherwise, returns the specified default value.
public Optional<T> GetValueOrOptional(Optional<T> defaultValue)
Parameters
defaultValueOptional<T>The Optional<T> object to be returned if the current Optional<T> object has no value.
Returns
- Optional<T>
Map<TOut>(Func<T, TOut>)
Transforms the value of the current Optional<T> object using the specified mapping function if it has a value; otherwise, returns an empty Optional<T> object.
public Optional<TOut> Map<TOut>(Func<T, TOut> mapper)
Parameters
mapperFunc<T, TOut>The mapping function to apply to the value.
Returns
- Optional<TOut>
Type Parameters
TOutThe type of the value returned by the mapping function.
ToString()
Returns a string representation of this object.
public override string ToString()
Returns
Operators
operator ==(Optional<T>, Optional<T>)
Determines whether the specified Optional<T> objects are equal.
public static bool operator ==(Optional<T> left, Optional<T> right)
Parameters
Returns
implicit operator Optional<T>(OptionalEmpty)
Creates a new object initialized to an empty value.
public static implicit operator Optional<T>(OptionalEmpty _)
Parameters
Returns
- Optional<T>
implicit operator Optional<T>(T)
Creates a new object initialized to a meaningful value.
public static implicit operator Optional<T>(T value)
Parameters
valueT
Returns
- Optional<T>
operator !=(Optional<T>, Optional<T>)
Determines whether the specified Optional<T> objects are not equal.
public static bool operator !=(Optional<T> left, Optional<T> right)