LazyInitializer 클래스
정의
초기화 지연 루틴을 제공합니다.Provides lazy initialization routines.
public ref class LazyInitializer abstract sealed
public static class LazyInitializer
type LazyInitializer = class
Public Class LazyInitializer
- 상속
-
LazyInitializer
예제
다음 예제에서는 EnsureInitialized를 사용 하 여 초기화가 이미 발생 했는지 여부와 상호 제외 잠금으로 사용할 개체를 추적 하는 부울 값을 사용 하 여 값을 지연 초기화 하는 방법을 보여 줍니다.The following example demonstrates how to use EnsureInitialized to lazily initialize a value using a Boolean value to track whether initialization has already happened and an object to use as the mutual exclusion lock.
Dim _data As ExpensiveData = Nothing
Dim _dataInitialized As Boolean = False
Dim _dataLock As Object = Nothing
' ...
Dim name = LazyInitializer.EnsureInitialized(_data, _dataInitialized, _dataLock)
ExpensiveData _data = null;
bool _dataInitialized = false;
object _dataLock = new object();
// ...
ExpensiveData dataToUse = LazyInitializer.EnsureInitialized(ref _data, ref _dataInitialized, ref _dataLock);
설명
이러한 루틴은 대상이 액세스 될 때 초기화 되었는지 확인 하기 위해 참조를 사용 하 여 초기화 되지 않은 전용 인스턴스를 할당할 필요가 없도록 합니다.These routines avoid needing to allocate a dedicated, lazy-initialization instance, instead using references to ensure targets have been initialized as they are accessed.
메서드
EnsureInitialized<T>(T) |
아직 초기화되지 않은 경우 형식의 매개 변수가 없는 생성자를 사용하여 대상 참조 형식을 초기화합니다.Initializes a target reference type with the type's parameterless constructor if it hasn't already been initialized. |
EnsureInitialized<T>(T, Boolean, Object) |
아직 초기화되지 않은 경우 해당 매개 변수가 없는 생성자를 사용하여 대상 참조 또는 값 형식을 초기화합니다.Initializes a target reference or value type with its parameterless constructor if it hasn't already been initialized. |
EnsureInitialized<T>(T, Boolean, Object, Func<T>) |
아직 초기화되지 않은 경우 지정된 함수를 사용하여 대상 참조 또는 값 형식을 초기화합니다.Initializes a target reference or value type by using a specified function if it hasn't already been initialized. |
EnsureInitialized<T>(T, Func<T>) |
아직 초기화되지 않은 경우 지정된 함수를 사용하여 대상 참조 형식을 초기화합니다.Initializes a target reference type by using a specified function if it hasn't already been initialized. |
EnsureInitialized<T>(T, Object, Func<T>) |
아직 초기화되지 않은 경우 지정된 함수로 대상 참조 형식을 초기화합니다.Initializes a target reference type with a specified function if it has not already been initialized. |
적용 대상
스레드 보안
의 메서드는 LazyInitializer 스레드로부터 안전 하며 여러 스레드에서 동시에 호출 될 수 있습니다.The methods of LazyInitializer are thread-safe and may be called from multiple threads concurrently.