Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Move System.Lazy to shared CoreLib partition (#9955)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Mar 4, 2017
1 parent da2cebb commit d22a221
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/mscorlib/System.Private.CoreLib.csproj
Expand Up @@ -385,7 +385,6 @@
<Compile Include="$(BclSourcesRoot)\System\GC.cs" />
<Compile Include="$(BclSourcesRoot)\System\Guid.cs" />
<Compile Include="$(BclSourcesRoot)\System\InsufficientMemoryException.cs" />
<Compile Include="$(BclSourcesRoot)\System\Lazy.cs" />
<Compile Include="$(BclSourcesRoot)\System\Int16.cs" />
<Compile Include="$(BclSourcesRoot)\System\Int32.cs" />
<Compile Include="$(BclSourcesRoot)\System\Int64.cs" />
Expand Down
Expand Up @@ -116,6 +116,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IObservable.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\IObserver.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\IProgress.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\Lazy.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\MarshalByRefObject.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\MemberAccessException.cs"/>
<Compile Include="$(MSBuildThisFileDirectory)System\MethodAccessException.cs"/>
Expand Down
@@ -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,
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -329,7 +323,7 @@ private void ViaFactory(LazyThreadSafetyMode mode)
{
Func<T> factory = _factory;
if (factory == null)
throw new InvalidOperationException(Environment.GetResourceString("Lazy_Value_RecursiveCallsToValue"));
throw new InvalidOperationException(SR.Lazy_Value_RecursiveCallsToValue);
_factory = null;

_value = factory();
Expand Down Expand Up @@ -464,7 +458,7 @@ private void OnSerializing(StreamingContext context)
/// </exception>
public override string ToString()
{
return IsValueCreated ? Value.ToString() : Environment.GetResourceString("Lazy_ToString_ValueNotCreated");
return IsValueCreated ? Value.ToString() : SR.Lazy_ToString_ValueNotCreated;
}

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

/// <summary>Constructs a new debugger view object for the provided Lazy object.</summary>
/// <param name="lazy">A Lazy object to browse in the debugger.</param>
public System_LazyDebugView(Lazy<T> lazy)
{
m_lazy = lazy;
_lazy = lazy;
}

/// <summary>Returns whether the Lazy object is initialized or not.</summary>
public bool IsValueCreated
{
get { return m_lazy.IsValueCreated; }
get { return _lazy.IsValueCreated; }
}

/// <summary>Returns the value of the Lazy object.</summary>
public T Value
{
get
{ return m_lazy.ValueForDebugDisplay; }
{ return _lazy.ValueForDebugDisplay; }
}

/// <summary>Returns the execution mode of the Lazy object</summary>
public LazyThreadSafetyMode? Mode
{
get { return m_lazy.Mode; }
get { return _lazy.Mode; }
}

/// <summary>Returns the execution mode of the Lazy object</summary>
public bool IsValueFaulted
{
get { return m_lazy.IsValueFaulted; }
get { return _lazy.IsValueFaulted; }
}
}
}
20 changes: 20 additions & 0 deletions src/mscorlib/src/SR.cs
Expand Up @@ -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"); }
}
}

0 comments on commit d22a221

Please sign in to comment.