UserDataSlot<TValue>
Uniquely identifies user data which can be associated
with any object.
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace DotNext
{
[StructLayout(LayoutKind.Auto)]
public readonly struct UserDataSlot<[System.Runtime.CompilerServices.Nullable(2)] TValue> : IEquatable<UserDataSlot<TValue>>
{
private static volatile int valueIndexCounter;
internal static readonly int TypeIndex = UserDataSlot.Allocate();
private readonly int valueIndex;
internal int ValueIndex => valueIndex - 1;
public bool IsAllocated => valueIndex != 0;
public UserDataSlot()
{
valueIndex = Interlocked.Increment(ref valueIndexCounter);
}
[Obsolete("Use public constructor to allocate the slot")]
[return: System.Runtime.CompilerServices.Nullable(new byte[] {
0,
1
})]
public static UserDataSlot<TValue> Allocate()
{
return new UserDataSlot<TValue>();
}
[System.Runtime.CompilerServices.NullableContext(1)]
public override string ToString()
{
return UserDataSlot.ToString(TypeIndex, valueIndex);
}
[CompilerGenerated]
private bool PrintMembers(StringBuilder builder)
{
builder.Append("IsAllocated = ");
builder.Append(IsAllocated.ToString());
return true;
}
public static bool operator !=(UserDataSlot<TValue> left, UserDataSlot<TValue> right)
{
return !(left == right);
}
public static bool operator ==(UserDataSlot<TValue> left, UserDataSlot<TValue> right)
{
return left.Equals(right);
}
[CompilerGenerated]
public override int GetHashCode()
{
return EqualityComparer<int>.Default.GetHashCode(valueIndex);
}
[CompilerGenerated]
public override bool Equals(object obj)
{
if (obj is UserDataSlot<TValue>)
return Equals((UserDataSlot<TValue>)obj);
return false;
}
[CompilerGenerated]
public bool Equals(UserDataSlot<TValue> other)
{
return EqualityComparer<int>.Default.Equals(valueIndex, other.valueIndex);
}
}
}