You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.5 KiB
63 lines
1.5 KiB
5 years ago
|
#if !NET_4_6
|
||
|
using System;
|
||
|
using System.Globalization;
|
||
|
using System.Threading;
|
||
|
|
||
|
namespace LinqInternal.Threading
|
||
|
{
|
||
|
[System.Diagnostics.DebuggerNonUserCode]
|
||
|
internal static class RuntimeUniqueIdProdiver
|
||
|
{
|
||
|
private static int _lastId = int.MinValue;
|
||
|
|
||
|
public static UniqueId GetNextId()
|
||
|
{
|
||
|
return new UniqueId(Interlocked.Increment(ref _lastId));
|
||
|
}
|
||
|
|
||
|
public struct UniqueId : IEquatable<UniqueId>
|
||
|
{
|
||
|
private readonly int _id;
|
||
|
|
||
|
internal UniqueId(int id)
|
||
|
{
|
||
|
_id = id;
|
||
|
}
|
||
|
|
||
|
public static bool operator !=(UniqueId x, UniqueId y)
|
||
|
{
|
||
|
return !x.Equals(y);
|
||
|
}
|
||
|
|
||
|
public static bool operator ==(UniqueId x, UniqueId y)
|
||
|
{
|
||
|
return x.Equals(y);
|
||
|
}
|
||
|
|
||
|
public bool Equals(UniqueId other)
|
||
|
{
|
||
|
return other._id.Equals(_id);
|
||
|
}
|
||
|
|
||
|
public override bool Equals(object obj)
|
||
|
{
|
||
|
if (obj is UniqueId)
|
||
|
{
|
||
|
return Equals((UniqueId)obj);
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public override int GetHashCode()
|
||
|
{
|
||
|
return _id;
|
||
|
}
|
||
|
|
||
|
public override string ToString()
|
||
|
{
|
||
|
return _id.ToString(CultureInfo.InvariantCulture);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|