Class LazyVariable<TOwner, TValue>
- Namespace
- AsmResolver
- Assembly
- AsmResolver.dll
Represents a variable that can be lazily initialized and/or assigned a new value.
public sealed class LazyVariable<TOwner, TValue>
Type Parameters
TOwner
The type of the owner of the variable.
TValue
The type of the values that the variable stores.
- Inheritance
-
LazyVariable<TOwner, TValue>
- Inherited Members
Remarks
For performance reasons, this class locks on itself for thread synchronization. Therefore, consumers should not lock instances of this class as a lock object to avoid dead-locks.
Constructors
LazyVariable(Func<TOwner, TValue?>)
Creates a new lazy variable and delays the initialization of the default value.
public LazyVariable(Func<TOwner, TValue?> getValue)
Parameters
getValue
Func<TOwner, TValue>The method to execute when initializing the default value.
LazyVariable(TValue)
Creates a new lazy variable and initialize it with a constant.
public LazyVariable(TValue value)
Parameters
value
TValueThe value to initialize the variable with.
Properties
IsInitialized
Gets a value indicating the value has been initialized.
public bool IsInitialized { get; }
Property Value
Methods
GetValue(TOwner)
Obtains the value stored in the variable, initializing the variable if necessary.
public TValue GetValue(TOwner owner)
Parameters
owner
TOwnerThe owner of the variable.
Returns
- TValue
The value.
SetValue(TValue)
Assigns a new value to the variable.
public void SetValue(TValue value)
Parameters
value
TValueThe new value.