Created
August 2, 2013 19:40
-
-
Save kumpera/6142815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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