16 lines
721 B
C#
16 lines
721 B
C#
namespace bts.utils {
|
|
// Mainly used as an optional override of nullable data arg.
|
|
// Explanation: the 'with' method pattern typically interprets null args to mean "keep the existing value."
|
|
// However, this makes it impossible for the caller to overwrite an existing value with null.
|
|
// This struct is designed (or at least was originally) to address this use-case.
|
|
// It is analagous to escape chars.
|
|
readonly struct OptionalNullable<T> where T : struct {
|
|
public OptionalNullable(T? value) => this.value = value;
|
|
|
|
public T? value { get; }
|
|
|
|
public static implicit operator OptionalNullable<T>(T? value) =>
|
|
new OptionalNullable<T>(value);
|
|
}
|
|
}
|