Skip to content

Commit 1992a33

Browse files
authored
Move System.Lazy to shared CoreLib partition (dotnet/coreclr#9955)
Commit migrated from dotnet/coreclr@d22a221
1 parent a64a230 commit 1992a33

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

src/coreclr/src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@
385385
<Compile Include="$(BclSourcesRoot)\System\GC.cs" />
386386
<Compile Include="$(BclSourcesRoot)\System\Guid.cs" />
387387
<Compile Include="$(BclSourcesRoot)\System\InsufficientMemoryException.cs" />
388-
<Compile Include="$(BclSourcesRoot)\System\Lazy.cs" />
389388
<Compile Include="$(BclSourcesRoot)\System\Int16.cs" />
390389
<Compile Include="$(BclSourcesRoot)\System\Int32.cs" />
391390
<Compile Include="$(BclSourcesRoot)\System\Int64.cs" />

src/coreclr/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<Compile Include="$(MSBuildThisFileDirectory)System\IObservable.cs"/>
117117
<Compile Include="$(MSBuildThisFileDirectory)System\IObserver.cs"/>
118118
<Compile Include="$(MSBuildThisFileDirectory)System\IProgress.cs"/>
119+
<Compile Include="$(MSBuildThisFileDirectory)System\Lazy.cs"/>
119120
<Compile Include="$(MSBuildThisFileDirectory)System\MarshalByRefObject.cs"/>
120121
<Compile Include="$(MSBuildThisFileDirectory)System\MemberAccessException.cs"/>
121122
<Compile Include="$(MSBuildThisFileDirectory)System\MethodAccessException.cs"/>

src/coreclr/src/mscorlib/src/System/Lazy.cs renamed to src/coreclr/src/mscorlib/shared/System/Lazy.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
4-
#pragma warning disable 0420
54

6-
// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
7-
//
8-
//
9-
//
105
// --------------------------------------------------------------------------------------
116
//
127
// A class that provides a simple, lightweight implementation of lazy initialization,
@@ -15,14 +10,13 @@
1510
//
1611
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
1712

18-
using System.Runtime;
19-
using System.Runtime.InteropServices;
20-
using System.Security;
13+
#pragma warning disable 0420
14+
2115
using System.Diagnostics;
16+
using System.Runtime.ExceptionServices;
17+
using System.Runtime.InteropServices;
2218
using System.Runtime.Serialization;
2319
using System.Threading;
24-
using System.Diagnostics.Contracts;
25-
using System.Runtime.ExceptionServices;
2620

2721
namespace System
2822
{
@@ -155,7 +149,7 @@ internal static LazyHelper Create(LazyThreadSafetyMode mode, bool useDefaultCons
155149
return new LazyHelper(state);
156150

157151
default:
158-
throw new ArgumentOutOfRangeException(nameof(mode), Environment.GetResourceString("Lazy_ctor_ModeInvalid"));
152+
throw new ArgumentOutOfRangeException(nameof(mode), SR.Lazy_ctor_ModeInvalid);
159153
}
160154
}
161155

@@ -167,7 +161,7 @@ internal static object CreateViaDefaultConstructor(Type type)
167161
}
168162
catch (MissingMethodException)
169163
{
170-
throw new MissingMemberException(Environment.GetResourceString("Lazy_CreateValue_NoParameterlessCtorForT"));
164+
throw new MissingMemberException(SR.Lazy_CreateValue_NoParameterlessCtorForT);
171165
}
172166
}
173167

@@ -329,7 +323,7 @@ private void ViaFactory(LazyThreadSafetyMode mode)
329323
{
330324
Func<T> factory = _factory;
331325
if (factory == null)
332-
throw new InvalidOperationException(Environment.GetResourceString("Lazy_Value_RecursiveCallsToValue"));
326+
throw new InvalidOperationException(SR.Lazy_Value_RecursiveCallsToValue);
333327
_factory = null;
334328

335329
_value = factory();
@@ -464,7 +458,7 @@ private void OnSerializing(StreamingContext context)
464458
/// </exception>
465459
public override string ToString()
466460
{
467-
return IsValueCreated ? Value.ToString() : Environment.GetResourceString("Lazy_ToString_ValueNotCreated");
461+
return IsValueCreated ? Value.ToString() : SR.Lazy_ToString_ValueNotCreated;
468462
}
469463

470464
/// <summary>Gets the value of the Lazy&lt;T&gt; for debugging display purposes.</summary>
@@ -531,38 +525,38 @@ internal T ValueForDebugDisplay
531525
internal sealed class System_LazyDebugView<T>
532526
{
533527
//The Lazy object being viewed.
534-
private readonly Lazy<T> m_lazy;
528+
private readonly Lazy<T> _lazy;
535529

536530
/// <summary>Constructs a new debugger view object for the provided Lazy object.</summary>
537531
/// <param name="lazy">A Lazy object to browse in the debugger.</param>
538532
public System_LazyDebugView(Lazy<T> lazy)
539533
{
540-
m_lazy = lazy;
534+
_lazy = lazy;
541535
}
542536

543537
/// <summary>Returns whether the Lazy object is initialized or not.</summary>
544538
public bool IsValueCreated
545539
{
546-
get { return m_lazy.IsValueCreated; }
540+
get { return _lazy.IsValueCreated; }
547541
}
548542

549543
/// <summary>Returns the value of the Lazy object.</summary>
550544
public T Value
551545
{
552546
get
553-
{ return m_lazy.ValueForDebugDisplay; }
547+
{ return _lazy.ValueForDebugDisplay; }
554548
}
555549

556550
/// <summary>Returns the execution mode of the Lazy object</summary>
557551
public LazyThreadSafetyMode? Mode
558552
{
559-
get { return m_lazy.Mode; }
553+
get { return _lazy.Mode; }
560554
}
561555

562556
/// <summary>Returns the execution mode of the Lazy object</summary>
563557
public bool IsValueFaulted
564558
{
565-
get { return m_lazy.IsValueFaulted; }
559+
get { return _lazy.IsValueFaulted; }
566560
}
567561
}
568562
}

src/coreclr/src/mscorlib/src/SR.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,4 +848,24 @@ internal static string UnknownError_Num
848848
{
849849
get { return Environment.GetResourceString("UnknownError_Num"); }
850850
}
851+
852+
internal static string Lazy_ctor_ModeInvalid
853+
{
854+
get { return Environment.GetResourceString("Lazy_ctor_ModeInvalid"); }
855+
}
856+
857+
internal static string Lazy_Value_RecursiveCallsToValue
858+
{
859+
get { return Environment.GetResourceString("Lazy_Value_RecursiveCallsToValue"); }
860+
}
861+
862+
internal static string Lazy_CreateValue_NoParameterlessCtorForT
863+
{
864+
get { return Environment.GetResourceString("Lazy_CreateValue_NoParameterlessCtorForT"); }
865+
}
866+
867+
internal static string Lazy_ToString_ValueNotCreated
868+
{
869+
get { return Environment.GetResourceString("Lazy_ToString_ValueNotCreated"); }
870+
}
851871
}

0 commit comments

Comments
 (0)