Struct PersistentNullable<T>
Wrapper for nullable types that preserves the value even when HasValue is false.
Inherited Members
Namespace: DotNet.Interpreter.Helper
Assembly: DotNet.Interpreter.Helper.dll
Syntax
public struct PersistentNullable<T> where T : struct
Type Parameters
Name | Description |
---|---|
T | Value type |
Remarks
Creates a new instance with the specified value.
Constructors
PersistentNullable(T)
Wrapper for nullable types that preserves the value even when HasValue is false.
Declaration
public PersistentNullable(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | Initial value |
Remarks
Creates a new instance with the specified value.
Properties
HasValue
Gets or sets the flag indicating whether a value is present.
Declaration
public bool HasValue { readonly get; set; }
Property Value
Type | Description |
---|---|
bool |
Value
Gets or sets the value.
Declaration
public T Value { readonly get; set; }
Property Value
Type | Description |
---|---|
T |
Methods
GetValueOrDefault(T)
Returns the value if HasValue is true, otherwise returns the default value.
Declaration
public readonly T GetValueOrDefault(T defaultValue = default)
Parameters
Type | Name | Description |
---|---|---|
T | defaultValue | Default value |
Returns
Type | Description |
---|---|
T | The value or the default value |
Reset()
Resets HasValue to false, preserving the value.
Declaration
public void Reset()
ToString()
Returns a string representation of the object.
Declaration
public override readonly string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
Operators
explicit operator T(PersistentNullable<T>)
Explicit conversion from PersistentNullable<T> to T
.
Declaration
public static explicit operator T(PersistentNullable<T> value)
Parameters
Type | Name | Description |
---|---|---|
PersistentNullable<T> | value |
Returns
Type | Description |
---|---|
T |
implicit operator T?(PersistentNullable<T>)
Implicit conversion from PersistentNullable<T> to Nullable<T>.
Declaration
public static implicit operator T?(PersistentNullable<T> persistent)
Parameters
Type | Name | Description |
---|---|---|
PersistentNullable<T> | persistent |
Returns
Type | Description |
---|---|
T? |
implicit operator PersistentNullable<T>(T?)
Implicit conversion from Nullable<T> to PersistentNullable<T>.
Declaration
public static implicit operator PersistentNullable<T>(T? nullable)
Parameters
Type | Name | Description |
---|---|---|
T? | nullable |
Returns
Type | Description |
---|---|
PersistentNullable<T> |
implicit operator PersistentNullable<T>(T)
Implicit conversion from T
to PersistentNullable<T>.
Declaration
public static implicit operator PersistentNullable<T>(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value |
Returns
Type | Description |
---|---|
PersistentNullable<T> |