LazyInitializer.EnsureInitialized Méthode

Définition

Initialise un type cible si ce n'est pas déjà fait.

Surcharges

EnsureInitialized<T>(T)

Initialise un type référence cible avec le constructeur sans paramètre du type, s’il n’a pas déjà été initialisé.

EnsureInitialized<T>(T, Func<T>)

Initialise un type référence cible à l'aide d'une fonction spécifiée s'il n'a pas déjà été initialisé.

EnsureInitialized<T>(T, Boolean, Object)

Initialise un type référence cible ou un type valeur avec son constructeur sans paramètre, s’il n’a pas déjà été initialisé.

EnsureInitialized<T>(T, Object, Func<T>)

Initialise un type référence cible ou avec une fonction spécifiée s’il n’a pas déjà été initialisé.

EnsureInitialized<T>(T, Boolean, Object, Func<T>)

Initialise un type référence cible ou un type valeur à l'aide d'une fonction spécifiée s'il n'a pas déjà été initialisé.

EnsureInitialized<T>(T)

Initialise un type référence cible avec le constructeur sans paramètre du type, s’il n’a pas déjà été initialisé.

public:
generic <typename T>
 where T : class static T EnsureInitialized(T % target);
public static T EnsureInitialized<T> (ref T target) where T : class;
public static T EnsureInitialized<T> (ref T? target) where T : class;
static member EnsureInitialized : 'T -> 'T (requires 'T : null)
Public Shared Function EnsureInitialized(Of T As Class) (ByRef target As T) As T

Paramètres de type

T

Type de la référence à initialiser.

Paramètres

target
T

Référence à initialiser si elle ne l’a pas déjà été. Si la référence est null, elle est considérée comme non initialisée ; sinon, elle est considérée comme initialisée.

Retours

T

Objet initialisé.

Exceptions

Autorisations pour accéder au constructeur de type T manquant.

Le type T n’a pas de constructeur sans paramètre.

Remarques

Cette méthode peut uniquement être utilisée sur les types de référence. Pour garantir l’initialisation des types de valeurs, consultez d’autres surcharges de EnsureInitialized.

Cette méthode peut être utilisée simultanément par plusieurs threads pour initialiser target.

Dans le cas où plusieurs threads accèdent simultanément à cette méthode, plusieurs instances peuvent T être créées, mais une seule sera stockée dans target et retournée. Dans une telle occurrence, cette méthode ne supprime pas les objets qui n’ont pas été stockés. Si ces objets doivent être supprimés, utilisez une surcharge qui prend et valueFactory supprime l’objet s’il ne fait pas référence au même objet stocké.

Voir aussi

S’applique à

EnsureInitialized<T>(T, Func<T>)

Initialise un type référence cible à l'aide d'une fonction spécifiée s'il n'a pas déjà été initialisé.

public:
generic <typename T>
 where T : class static T EnsureInitialized(T % target, Func<T> ^ valueFactory);
public static T EnsureInitialized<T> (ref T target, Func<T> valueFactory) where T : class;
public static T EnsureInitialized<T> (ref T? target, Func<T> valueFactory) where T : class;
static member EnsureInitialized : 'T * Func<'T (requires 'T : null)> -> 'T (requires 'T : null)
Public Shared Function EnsureInitialized(Of T As Class) (ByRef target As T, valueFactory As Func(Of T)) As T

Paramètres de type

T

Type de la référence à initialiser.

Paramètres

target
T

Référence à initialiser si elle ne l’a pas déjà été.

valueFactory
Func<T>

Fonction appelée pour initialiser la référence.

Retours

T

Objet initialisé.

Exceptions

Le type T n’a pas de constructeur sans paramètre.

valueFactory a retourné null (Nothing en Visual Basic).

Remarques

Cette méthode peut uniquement être utilisée sur les types de référence et valueFactory ne pas retourner une référence Null (Rien dans Visual Basic). Pour garantir l’initialisation des types de valeur ou pour autoriser les types de référence Null, consultez d’autres surcharges de EnsureInitialized.

Cette méthode peut être utilisée simultanément par plusieurs threads pour initialiser target.

Dans le cas où plusieurs threads accèdent simultanément à cette méthode, plusieurs instances de T peuvent être créées, mais une seule sera stockée dans target. Dans une telle occurrence, cette méthode ne supprime pas les objets qui n’ont pas été stockés. Si ces objets doivent être supprimés, il est à l’appelant de déterminer si un objet n’a pas été utilisé, puis de supprimer l’objet de manière appropriée.

Voir aussi

S’applique à

EnsureInitialized<T>(T, Boolean, Object)

Initialise un type référence cible ou un type valeur avec son constructeur sans paramètre, s’il n’a pas déjà été initialisé.

public:
generic <typename T>
 static T EnsureInitialized(T % target, bool % initialized, System::Object ^ % syncLock);
public static T EnsureInitialized<T> (ref T target, ref bool initialized, ref object syncLock);
public static T EnsureInitialized<T> (ref T target, ref bool initialized, ref object? syncLock);
static member EnsureInitialized : 'T * bool * obj -> 'T
Public Shared Function EnsureInitialized(Of T) (ByRef target As T, ByRef initialized As Boolean, ByRef syncLock As Object) As T

Paramètres de type

T

Type de la référence à initialiser.

Paramètres

target
T

Référence ou valeur de type T à initialiser si elle ne l’a pas déjà été.

initialized
Boolean

Référence à une valeur booléenne qui détermine si la cible a déjà été initialisée.

syncLock
Object

Référence à un objet utilisé comme verrou mutuellement exclusif pour l'initialisation de target. Si syncLock est null null, un nouvel objet est instancié.

Retours

T

Objet initialisé.

Exceptions

Autorisations pour accéder au constructeur de type T manquant.

Le type T n’a pas de constructeur sans paramètre.

Remarques

Si initialized elle est spécifiée comme true, aucune initialisation supplémentaire ne se produit.

Voir aussi

S’applique à

EnsureInitialized<T>(T, Object, Func<T>)

Initialise un type référence cible ou avec une fonction spécifiée s’il n’a pas déjà été initialisé.

public:
generic <typename T>
 where T : class static T EnsureInitialized(T % target, System::Object ^ % syncLock, Func<T> ^ valueFactory);
public static T EnsureInitialized<T> (ref T? target, ref object? syncLock, Func<T> valueFactory) where T : class;
public static T EnsureInitialized<T> (ref T target, ref object syncLock, Func<T> valueFactory) where T : class;
static member EnsureInitialized : 'T * obj * Func<'T (requires 'T : null)> -> 'T (requires 'T : null)
Public Shared Function EnsureInitialized(Of T As Class) (ByRef target As T, ByRef syncLock As Object, valueFactory As Func(Of T)) As T

Paramètres de type

T

Type de la référence à initialiser.

Paramètres

target
T

Référence à initialiser si elle ne l’a pas déjà été. Si la référence est null, elle est considérée comme non initialisée ; sinon, elle est considérée comme initialisée.

syncLock
Object

Référence à un objet utilisé comme verrou mutuellement exclusif pour l'initialisation de target. Si syncLock est null null, un nouvel objet est instancié.

valueFactory
Func<T>

Méthode à appeler pour initialiser target.

Retours

T

Objet initialisé.

S’applique à

EnsureInitialized<T>(T, Boolean, Object, Func<T>)

Initialise un type référence cible ou un type valeur à l'aide d'une fonction spécifiée s'il n'a pas déjà été initialisé.

public:
generic <typename T>
 static T EnsureInitialized(T % target, bool % initialized, System::Object ^ % syncLock, Func<T> ^ valueFactory);
public static T EnsureInitialized<T> (ref T target, ref bool initialized, ref object syncLock, Func<T> valueFactory);
public static T EnsureInitialized<T> (ref T target, ref bool initialized, ref object? syncLock, Func<T> valueFactory);
static member EnsureInitialized : 'T * bool * obj * Func<'T> -> 'T
Public Shared Function EnsureInitialized(Of T) (ByRef target As T, ByRef initialized As Boolean, ByRef syncLock As Object, valueFactory As Func(Of T)) As T

Paramètres de type

T

Type de la référence à initialiser.

Paramètres

target
T

Référence ou valeur de type T à initialiser si elle ne l’a pas déjà été.

initialized
Boolean

Référence à une valeur booléenne qui détermine si la cible a déjà été initialisée.

syncLock
Object

Référence à un objet utilisé comme verrou mutuellement exclusif pour l'initialisation de target. Si syncLock est null null, un nouvel objet est instancié.

valueFactory
Func<T>

Fonction appelée pour initialiser la référence ou la valeur.

Retours

T

Objet initialisé.

Exceptions

Autorisations pour accéder au constructeur de type T manquant.

Le type T n’a pas de constructeur sans paramètre.

Remarques

Si initialized elle est spécifiée comme true, aucune initialisation supplémentaire ne se produit.

Voir aussi

S’applique à