IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
AccessorUtil.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3
5{
6
7 static class AccessorUtil
8 {
9
16 public static T LazyGet<T>(ref T location, Func<T> create)
17 where T : class
18 {
19 if (create is null)
20 throw new ArgumentNullException(nameof(create));
21
22 if (location == null)
23 Interlocked.CompareExchange(ref location, create(), null);
24
25 return location;
26 }
27
28 }
29
30}
System.Threading.Interlocked Interlocked
static T LazyGet< T >(ref T location, Func< T > create)
Gets the value at the given location or initializes it if null.