Table of Contents

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

T

The type of the optionally present value.

Inherited Members

Constructors

Optional(T)

Constructs an Optional<T> with a meaningful value.

public Optional(T value)

Parameters

value T

Properties

HasValue

Returns true if the Value will return a meaningful value.

public bool HasValue { get; }

Property Value

bool

Value

Gets the value of the current object. Not meaningful unless HasValue returns true.

public T Value { get; }

Property Value

T

The value if HasValue is true; otherwise, the default value for type T.

Remarks

Unlike Value, this property does not throw an exception when HasValue is false.

Methods

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

defaultValue T

The 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

defaultValue Optional<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

mapper Func<T, TOut>

The mapping function to apply to the value.

Returns

Optional<TOut>

Type Parameters

TOut

The type of the value returned by the mapping function.

ToString()

Returns a string representation of this object.

public override string ToString()

Returns

string

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

left Optional<T>
right Optional<T>

Returns

bool

implicit operator Optional<T>(OptionalEmpty)

Creates a new object initialized to an empty value.

public static implicit operator Optional<T>(OptionalEmpty _)

Parameters

_ OptionalEmpty

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

value T

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)

Parameters

left Optional<T>
right Optional<T>

Returns

bool