LazyInitializer::EnsureInitialized<T> Method (T%, Boolean%, Object^%, Func<T>^)

.NET Framework (current version)
 

Initializes a target reference or value type by using a specified function if it hasn't already been initialized.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public:
generic<typename T>
static T EnsureInitialized(
	T% target,
	bool% initialized,
	Object^% syncLock,
	Func<T>^ valueFactory
)

Parameters

target
Type: T%

A reference or value of type T to initialize if it hasn't already been initialized.

initialized
Type: System::Boolean%

A reference to a Boolean value that determines whether the target has already been initialized.

syncLock
Type: System::Object^%

A reference to an object used as the mutually exclusive lock for initializing target. If syncLock is null, a new object will be instantiated.

valueFactory
Type: System::Func<T>^

The function that is called to initialize the reference or value.

Return Value

Type: T

The initialized value of type T.

Type Parameters

T

The type of the reference to be initialized.

Exception Condition
MemberAccessException

Permissions to access the constructor of type T were missing.

MissingMemberException

Type T does not have a default constructor.

If intialized is specified as true, then no further initialization occurs.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1
Return to top
Show: