Browse Source

LazyInitializer.EnsureInitialized does not allow null as return value. Use LazyInit instead.

pull/3265/head
Siegfried Pammer 2 years ago
parent
commit
76cc084dcd
  1. 13
      ICSharpCode.ILSpyX/LoadedAssembly.cs

13
ICSharpCode.ILSpyX/LoadedAssembly.cs

@ -209,14 +209,19 @@ namespace ICSharpCode.ILSpyX
/// </remarks> /// </remarks>
public ICompilation? GetTypeSystemOrNull() public ICompilation? GetTypeSystemOrNull()
{ {
return LazyInitializer.EnsureInitialized(ref this.typeSystem, () => { var value = Volatile.Read(ref this.typeSystem);
if (value == null)
{
var module = GetMetadataFileOrNull(); var module = GetMetadataFileOrNull();
if (module == null || module.IsMetadataOnly) if (module == null || module.IsMetadataOnly)
return null!; return null;
return new SimpleCompilation( value = new SimpleCompilation(
module.WithOptions(TypeSystemOptions.Default | TypeSystemOptions.Uncached | TypeSystemOptions.KeepModifiers), module.WithOptions(TypeSystemOptions.Default | TypeSystemOptions.Uncached | TypeSystemOptions.KeepModifiers),
MinimalCorlib.Instance); MinimalCorlib.Instance);
}); value = LazyInit.GetOrSet(ref this.typeSystem, value);
}
return value;
} }
readonly object typeSystemWithOptionsLockObj = new object(); readonly object typeSystemWithOptionsLockObj = new object();

Loading…
Cancel
Save