Class CMSLazy<TValue>
Provides lazy initialization
public class CMSLazy<TValue>
Type Parameters
TValue
- Inheritance
-
objectCMSLazy<TValue>
- Derived
- Extension Methods
Constructors
CMSLazy(Func<TValue>, TValue)
Constructor
public CMSLazy(Func<TValue> initializer, TValue defaultValue = default)
Parameters
initializer
Func<TValue>Value initialization function
defaultValue
TValueDefault value
Properties
AllowCloneForNewThread
If true, the item is copied for the new thread
public bool AllowCloneForNewThread { get; set; }
Property Value
- bool
DefaultValue
Default value
public TValue DefaultValue { get; protected set; }
Property Value
- TValue
Initializer
Value initialization function
protected Func<TValue> Initializer { get; set; }
Property Value
- Func<TValue>
IsValueCreated
Returns true if the value was already created
public bool IsValueCreated { get; }
Property Value
- bool
RequestStockKey
Defines the key under which the object value should be stored in the request stock helper. If set, the object exists only within the particular request
public string RequestStockKey { get; set; }
Property Value
- string
Value
Gets or sets the object value
public virtual TValue Value { get; set; }
Property Value
- TValue
Methods
CanInitialize()
Returns true, if the object value can initialize
protected virtual bool CanInitialize()
Returns
- bool
NewValue()
Creates a new value using the initializer
protected virtual TValue NewValue()
Returns
- TValue
Reset()
Resets the state of the object to re-initialize the value on the next request
public void Reset()
Operators
implicit operator TValue(CMSLazy<TValue>)
Implicit operator for conversion of the lazy object to its value type
public static implicit operator TValue(CMSLazy<TValue> obj)
Parameters
obj
CMSLazy<TValue>Object to convert
Returns
- TValue