mscorlib(4.0.0.0) API with additions
System.Lazy< T > Class Template Reference

Provides support for lazy initialization. More...

Inheritance diagram for System.Lazy< T >:
[legend]

Public Member Functions

 Lazy ()
 Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the default constructor of the target type is used. More...
 
 Lazy (Func< T > valueFactory)
 Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the specified initialization function is used. More...
 
 Lazy? (bool isThreadSafe)
 Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the default constructor of the target type and the specified initialization mode are used. More...
 
 Lazy (LazyThreadSafetyMode mode)
 Initializes a new instance of the T:System.Lazy`1 class that uses the default constructor of T and the specified thread-safety mode. More...
 
 Lazy? (Func< T > valueFactory, bool isThreadSafe)
 Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the specified initialization function and initialization mode are used. More...
 
 Lazy (Func< T > valueFactory, LazyThreadSafetyMode mode)
 Initializes a new instance of the T:System.Lazy`1 class that uses the specified initialization function and thread-safety mode. More...
 
override string ToString ()
 Creates and returns a string representation of the P:System.Lazy`1.Value property for this instance. More...
 

Properties

bool IsValueCreated [get]
 Gets a value that indicates whether a value has been created for this T:System.Lazy`1 instance. More...
 
T Value [get]
 Gets the lazily initialized value of the current T:System.Lazy`1 instance. More...
 

Detailed Description

Provides support for lazy initialization.

Template Parameters
TThe type of object that is being lazily initialized.

Definition at line 18 of file Lazy.cs.

Constructor & Destructor Documentation

◆ Lazy() [1/4]

System.Lazy< T >.Lazy ( )

Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the default constructor of the target type is used.

Definition at line 128 of file Lazy.cs.

◆ Lazy() [2/4]

System.Lazy< T >.Lazy ( Func< T valueFactory)

Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the specified initialization function is used.

Parameters
valueFactoryThe delegate that is invoked to produce the lazily initialized value when it is needed.
Exceptions
T:System.ArgumentNullExceptionvalueFactory is null.

Definition at line 138 of file Lazy.cs.

◆ Lazy() [3/4]

Initializes a new instance of the T:System.Lazy`1 class that uses the default constructor of T and the specified thread-safety mode.

Parameters
modeOne of the enumeration values that specifies the thread safety mode.
Exceptions
T:System.ArgumentOutOfRangeExceptionmode contains an invalid value.

Definition at line 157 of file Lazy.cs.

◆ Lazy() [4/4]

System.Lazy< T >.Lazy ( Func< T valueFactory,
LazyThreadSafetyMode  mode 
)

Initializes a new instance of the T:System.Lazy`1 class that uses the specified initialization function and thread-safety mode.

Parameters
valueFactoryThe delegate that is invoked to produce the lazily initialized value when it is needed.
modeOne of the enumeration values that specifies the thread safety mode.
Exceptions
T:System.ArgumentOutOfRangeExceptionmode contains an invalid value.
T:System.ArgumentNullExceptionvalueFactory is null.

Definition at line 182 of file Lazy.cs.

Member Function Documentation

◆ Lazy?() [1/2]

System.Lazy< T >.Lazy? ( bool  isThreadSafe)

Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the default constructor of the target type and the specified initialization mode are used.

Parameters
isThreadSafetrue to make this instance usable concurrently by multiple threads; false to make the instance usable by only one thread at a time.

Definition at line 147 of file Lazy.cs.

◆ Lazy?() [2/2]

System.Lazy< T >.Lazy? ( Func< T valueFactory,
bool  isThreadSafe 
)

Initializes a new instance of the T:System.Lazy`1 class. When lazy initialization occurs, the specified initialization function and initialization mode are used.

Parameters
valueFactoryThe delegate that is invoked to produce the lazily initialized value when it is needed.
isThreadSafetrue to make this instance usable concurrently by multiple threads; false to make this instance usable by only one thread at a time.
Exceptions
T:System.ArgumentNullExceptionvalueFactory is null.

Definition at line 169 of file Lazy.cs.

◆ ToString()

override string System.Lazy< T >.ToString ( )

Creates and returns a string representation of the P:System.Lazy`1.Value property for this instance.

Returns
The result of calling the M:System.Object.ToString method on the P:System.Lazy`1.Value property for this instance, if the value has been created (that is, if the P:System.Lazy`1.IsValueCreated property returns true). Otherwise, a string indicating that the value has not been created.
Exceptions
T:System.NullReferenceExceptionThe P:System.Lazy`1.Value property is null.

Definition at line 217 of file Lazy.cs.

Property Documentation

◆ IsValueCreated

bool System.Lazy< T >.IsValueCreated
get

Gets a value that indicates whether a value has been created for this T:System.Lazy`1 instance.

Returns
true if a value has been created for this T:System.Lazy`1 instance; otherwise, false.

Definition at line 86 of file Lazy.cs.

◆ Value

T System.Lazy< T >.Value
get

Gets the lazily initialized value of the current T:System.Lazy`1 instance.

Returns
The lazily initialized value of the current T:System.Lazy`1 instance.
Exceptions
T:System.MemberAccessExceptionThe T:System.Lazy`1 instance is initialized to use the default constructor of the type that is being lazily initialized, and permissions to access the constructor are missing.
T:System.MissingMemberExceptionThe T:System.Lazy`1 instance is initialized to use the default constructor of the type that is being lazily initialized, and that type does not have a public, parameterless constructor.
T:System.InvalidOperationExceptionThe initialization function tries to access P:System.Lazy`1.Value on this instance.

Definition at line 106 of file Lazy.cs.


The documentation for this class was generated from the following file: