Lazy Properties
Lazy Properties are a special kind of property that will be initialized delayed, on first access.
A property can be marked as lazy by prefixing the Property
keyword with Lazy
. Lazy properties must provide an initializer, and cannot provide custom getter or setter code.
Under the hood, the compiler will generate a property getter that will ensure the initializer is run, in a thread-safe fashion, the first and only the first time the property is read.
Public Lazy Property ExpensiveToCreate = New ExpensiveObject()
If a lazy property is not accessed as part of the execution flow of a program, the initializer will never run. A writable lazy property can still be explicitly set to a value, from code, to override the default value. If this happens before the property is read the first time, the initializer will never be executed.
See Also
Lazy
Aspect- Lazy Properties in Oxygene