Assignable<T> Record
Generic record that wraps a value of type T and tracks whether it has been explicitly assigned.
Remarks
Assignable<T> is similar to Nullable<T> but is designed to track assignment state rather than null state. This is useful in scenarios where you need to distinguish between a value that was never set and one that was explicitly assigned, such as partial updates in ORM operations or REST API patch requests.
An unassigned instance has IsAssigned set to False. Accessing the Value property of an unassigned instance raises EUnassignedConvertException. Use ValueOrDefault to safely retrieve the value without raising an exception.
Implicit operators allow seamless conversion between T and Assignable<T>.
Syntax
Unit: Bcl.Types.Assignable
Assignable<T> = record;
Constructors
| Name | Description |
|---|---|
| Create | Creates a new Assignable<T> instance with the specified value, marking it as assigned. |
Operators
| Name | Description |
|---|---|
| Equality | Adapts the = operator so it returns true when both instances have the same values. |
| Inequality | Adapts the <> operator so it returns true when both instances have different values. |
Properties
| Name | Description |
|---|---|
| IsAssigned | Indicates whether a value has been explicitly assigned to this instance. |
| Value | Gets or sets the wrapped value. |
| ValueOrDefault | Gets the wrapped value if assigned, or the default value for type T if not assigned. |
| Empty | Returns a new unassigned Assignable<T> instance. |