Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created August 2, 2013 19:40
Show Gist options
  • Select an option

  • Save kumpera/6142815 to your computer and use it in GitHub Desktop.

Select an option

Save kumpera/6142815 to your computer and use it in GitHub Desktop.
class HiddenReference<T>
{
int id;
static Dictionary<int, T> table = new Dictionary<int, T> ();
static int idgen = 0;
public HiddenReference () {
lock (table) { id = idgen ++; }
}
~HiddenReference () {
lock (table) { table.Remove (id); }
}
public T Value {
get { lock (table) {return table [id]; } }
set { lock (table) { table [id] = value; } }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment