From d22a22140ad29e90e1a5ee44e5288418b2b7d3d4 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 4 Mar 2017 00:40:56 -0800 Subject: [PATCH] Move System.Lazy to shared CoreLib partition (#9955) --- src/mscorlib/System.Private.CoreLib.csproj | 1 - .../System.Private.CoreLib.Shared.projitems | 1 + src/mscorlib/{src => shared}/System/Lazy.cs | 34 ++++++++----------- src/mscorlib/src/SR.cs | 20 +++++++++++ 4 files changed, 35 insertions(+), 21 deletions(-) rename src/mscorlib/{src => shared}/System/Lazy.cs (96%) diff --git a/src/mscorlib/System.Private.CoreLib.csproj b/src/mscorlib/System.Private.CoreLib.csproj index 2990d76427ce..5d5eb4925986 100644 --- a/src/mscorlib/System.Private.CoreLib.csproj +++ b/src/mscorlib/System.Private.CoreLib.csproj @@ -385,7 +385,6 @@ - diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index 2ca7c35bd422..09b940c4d07e 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -116,6 +116,7 @@ + diff --git a/src/mscorlib/src/System/Lazy.cs b/src/mscorlib/shared/System/Lazy.cs similarity index 96% rename from src/mscorlib/src/System/Lazy.cs rename to src/mscorlib/shared/System/Lazy.cs index 58fdd4a38a44..d59f67849fc6 100644 --- a/src/mscorlib/src/System/Lazy.cs +++ b/src/mscorlib/shared/System/Lazy.cs @@ -1,12 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#pragma warning disable 0420 -// =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+ -// -// -// // -------------------------------------------------------------------------------------- // // A class that provides a simple, lightweight implementation of lazy initialization, @@ -15,14 +10,13 @@ // // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- -using System.Runtime; -using System.Runtime.InteropServices; -using System.Security; +#pragma warning disable 0420 + using System.Diagnostics; +using System.Runtime.ExceptionServices; +using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Threading; -using System.Diagnostics.Contracts; -using System.Runtime.ExceptionServices; namespace System { @@ -155,7 +149,7 @@ internal static LazyHelper Create(LazyThreadSafetyMode mode, bool useDefaultCons return new LazyHelper(state); default: - throw new ArgumentOutOfRangeException(nameof(mode), Environment.GetResourceString("Lazy_ctor_ModeInvalid")); + throw new ArgumentOutOfRangeException(nameof(mode), SR.Lazy_ctor_ModeInvalid); } } @@ -167,7 +161,7 @@ internal static object CreateViaDefaultConstructor(Type type) } catch (MissingMethodException) { - throw new MissingMemberException(Environment.GetResourceString("Lazy_CreateValue_NoParameterlessCtorForT")); + throw new MissingMemberException(SR.Lazy_CreateValue_NoParameterlessCtorForT); } } @@ -329,7 +323,7 @@ private void ViaFactory(LazyThreadSafetyMode mode) { Func factory = _factory; if (factory == null) - throw new InvalidOperationException(Environment.GetResourceString("Lazy_Value_RecursiveCallsToValue")); + throw new InvalidOperationException(SR.Lazy_Value_RecursiveCallsToValue); _factory = null; _value = factory(); @@ -464,7 +458,7 @@ private void OnSerializing(StreamingContext context) /// public override string ToString() { - return IsValueCreated ? Value.ToString() : Environment.GetResourceString("Lazy_ToString_ValueNotCreated"); + return IsValueCreated ? Value.ToString() : SR.Lazy_ToString_ValueNotCreated; } /// Gets the value of the Lazy<T> for debugging display purposes. @@ -531,38 +525,38 @@ internal T ValueForDebugDisplay internal sealed class System_LazyDebugView { //The Lazy object being viewed. - private readonly Lazy m_lazy; + private readonly Lazy _lazy; /// Constructs a new debugger view object for the provided Lazy object. /// A Lazy object to browse in the debugger. public System_LazyDebugView(Lazy lazy) { - m_lazy = lazy; + _lazy = lazy; } /// Returns whether the Lazy object is initialized or not. public bool IsValueCreated { - get { return m_lazy.IsValueCreated; } + get { return _lazy.IsValueCreated; } } /// Returns the value of the Lazy object. public T Value { get - { return m_lazy.ValueForDebugDisplay; } + { return _lazy.ValueForDebugDisplay; } } /// Returns the execution mode of the Lazy object public LazyThreadSafetyMode? Mode { - get { return m_lazy.Mode; } + get { return _lazy.Mode; } } /// Returns the execution mode of the Lazy object public bool IsValueFaulted { - get { return m_lazy.IsValueFaulted; } + get { return _lazy.IsValueFaulted; } } } } diff --git a/src/mscorlib/src/SR.cs b/src/mscorlib/src/SR.cs index 10f6d21cc893..480eb1ff45bb 100644 --- a/src/mscorlib/src/SR.cs +++ b/src/mscorlib/src/SR.cs @@ -848,4 +848,24 @@ internal static string UnknownError_Num { get { return Environment.GetResourceString("UnknownError_Num"); } } + + internal static string Lazy_ctor_ModeInvalid + { + get { return Environment.GetResourceString("Lazy_ctor_ModeInvalid"); } + } + + internal static string Lazy_Value_RecursiveCallsToValue + { + get { return Environment.GetResourceString("Lazy_Value_RecursiveCallsToValue"); } + } + + internal static string Lazy_CreateValue_NoParameterlessCtorForT + { + get { return Environment.GetResourceString("Lazy_CreateValue_NoParameterlessCtorForT"); } + } + + internal static string Lazy_ToString_ValueNotCreated + { + get { return Environment.GetResourceString("Lazy_ToString_ValueNotCreated"); } + } }