Last active
August 29, 2015 14:22
-
-
Save coreyhaines/8545bc5624d50bdae14c to your computer and use it in GitHub Desktop.
Type-based stack
This file contains 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 TypeStack { | |
public void push(T obj); | |
public T pop<T>(); | |
public T peek<T>(); | |
} | |
var stack = new TypeStack(); | |
stack.push("hello"); | |
var o = new OtherType(); | |
stack.push(o); | |
AssertSame(o, stack.peek<typeof OtherType>()); |
Doing the pop trick was something that I didn't use a lot, but when I needed it, sure came in handy.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think I'm missing something, as this seems straight-forward to do. Internal dictionary of T -> Stack ?