I ran across the following class in a C# XNA graphics api and I am not sure what it does or that it needs to be so obscure. (T is constrained to be a struct in a parent class)
static class Ident
{
static object sync = new object();
static volatile int index = 0;
static int Index
{
get
{
lock (sync)
return index++;
}
}
class Type<T>
{
public static int id = Index;
}
public static int TypeIndex<T>()
{
return Type<T>.id;
}
}
The API makes only on call to this static class: int index = Ident.TypeIndex<T>();