6 [__DynamicallyInvokable]
7 [HostProtection(
SecurityAction.LinkDemand, Synchronization =
true, ExternalThreading =
true)]
16 [__DynamicallyInvokable]
23 return EnsureInitializedCore(ref target, LazyHelpers<T>.s_activatorFactorySelector);
34 [__DynamicallyInvokable]
41 return EnsureInitializedCore(ref target, valueFactory);
44 private static T EnsureInitializedCore<T>(ref T target, Func<T> valueFactory) where
T :
class 46 T val = valueFactory();
51 Interlocked.CompareExchange(ref target, val,
null);
63 [__DynamicallyInvokable]
70 return EnsureInitializedCore(ref target, ref initialized, ref syncLock, LazyHelpers<T>.s_activatorFactorySelector);
82 [__DynamicallyInvokable]
83 public static T EnsureInitialized<T>(ref T target, ref
bool initialized, ref
object syncLock, Func<T> valueFactory)
89 return EnsureInitializedCore(ref target, ref initialized, ref syncLock, valueFactory);
92 private static T EnsureInitializedCore<T>(ref T target, ref
bool initialized, ref
object syncLock, Func<T> valueFactory)
94 object obj = syncLock;
97 object obj2 =
new object();
106 if (!Volatile.Read(ref initialized))
108 target = valueFactory();
109 Volatile.Write(ref initialized, value:
true);
static T EnsureInitialized< T >(ref T target)
Initializes a target reference type with the type's default constructor if it hasn't already been ini...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Provides lazy initialization routines.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
Contains methods for performing volatile memory operations.
static bool Read(ref bool location)
Reads the value of the specified field. On systems that require it, inserts a memory barrier that pre...
The exception that is thrown when a method call is invalid for the object's current state.
Provides atomic operations for variables that are shared by multiple threads.