Class SetOnce<T>
- Namespace
- FishMMO.Shared
- Assembly
- FishMMO-SharedUtility.dll
Thread-safe wrapper that allows a value to be set only once. Optimized for lock-free reads after the initial assignment. Uses both a volatile isSet guard and the lock's implicit memory barrier to ensure all threads see the written value on weak memory-model architectures (ARM, ARM64).
public class SetOnce<T>
Type Parameters
T
- Inheritance
-
SetOnce<T>
- Inherited Members
Properties
IsSet
Returns true if the value has already been assigned.
public bool IsSet { get; }
Property Value
Value
Gets or sets the value. Can only be set once; subsequent sets are ignored. Reading before a value has been set throws InvalidOperationException.
public T Value { get; set; }
Property Value
- T
Operators
implicit operator T?(SetOnce<T>?)
Implicit conversion operator for easier usage in logic.
Returns default(T) if the wrapper is null.
Throws InvalidOperationException if the value is not yet set.
public static implicit operator T?(SetOnce<T>? convert)
Parameters
convertSetOnce<T>
Returns
- T