Skip to content

Commit

Permalink
Rename Net5CompatImpl to CompatImpl (#108881)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperk81 authored Oct 16, 2024
1 parent 7056bbd commit def5e32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Progress.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Random.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Random.ImplBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Random.Net5CompatImpl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Random.CompatImpl.cs" />
<Compile Condition="'$(Is64Bit)' != 'true'" Include="$(MSBuildThisFileDirectory)System\Random.Xoshiro128StarStarImpl.cs" />
<Compile Condition="'$(Is64Bit)' == 'true'" Include="$(MSBuildThisFileDirectory)System\Random.Xoshiro256StarStarImpl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Range.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public partial class Random
/// Provides an implementation used for compatibility with cases where a seed is specified
/// and thus the sequence produced historically could have been relied upon.
/// </summary>
private sealed class Net5CompatSeedImpl : ImplBase
private sealed class CompatSeedImpl : ImplBase
{
private CompatPrng _prng; // mutable struct; do not make this readonly

public Net5CompatSeedImpl(int seed) =>
public CompatSeedImpl(int seed) =>
_prng.EnsureInitialized(seed);

public override double Sample() => _prng.Sample();
Expand Down Expand Up @@ -104,7 +104,7 @@ public override float NextSingle()
/// Provides an implementation used for compatibility with cases where a derived type may
/// reasonably expect its overrides to be called.
/// </summary>
private sealed class Net5CompatDerivedImpl : ImplBase
private sealed class CompatDerivedImpl : ImplBase
{
/// <summary>Reference to the <see cref="Random"/> containing this implementation instance.</summary>
/// <remarks>Used to ensure that any calls to other virtual members are performed using the Random-derived instance, if one exists.</remarks>
Expand All @@ -114,9 +114,9 @@ private sealed class Net5CompatDerivedImpl : ImplBase
/// <summary>Lazily-initialized algorithm backing this instance.</summary>
private CompatPrng _prng; // mutable struct; do not make this readonly

public Net5CompatDerivedImpl(Random parent) : this(parent, Shared.Next()) { }
public CompatDerivedImpl(Random parent) : this(parent, Shared.Next()) { }

public Net5CompatDerivedImpl(Random parent, int seed)
public CompatDerivedImpl(Random parent, int seed)
{
_parent = parent;
_seed = seed;
Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Random.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Random() =>
// With no seed specified, if this is the base type, we can implement this however we like.
// If it's a derived type, for compat we respect the previous implementation, so that overrides
// are called as they were previously.
_impl = GetType() == typeof(Random) ? new XoshiroImpl() : new Net5CompatDerivedImpl(this);
_impl = GetType() == typeof(Random) ? new XoshiroImpl() : new CompatDerivedImpl(this);

/// <summary>Initializes a new instance of the Random class, using the specified seed value.</summary>
/// <param name="Seed">
Expand All @@ -41,7 +41,7 @@ public Random(int Seed) =>
// With a custom seed, if this is the base Random class, we still need to respect the same algorithm that's been
// used in the past, but we can do so without having to deal with calling the right overrides in a derived type.
// If this is a derived type, we need to handle always using the same overrides we've done previously.
_impl = GetType() == typeof(Random) ? new Net5CompatSeedImpl(Seed) : new Net5CompatDerivedImpl(this, Seed);
_impl = GetType() == typeof(Random) ? new CompatSeedImpl(Seed) : new CompatDerivedImpl(this, Seed);

/// <summary>Constructor used by <see cref="ThreadSafeRandom"/>.</summary>
/// <param name="isThreadSafeRandom">Must be true.</param>
Expand Down

0 comments on commit def5e32

Please sign in to comment.