Skip to content

Instantly share code, notes, and snippets.

@coreyhaines
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coreyhaines/8545bc5624d50bdae14c to your computer and use it in GitHub Desktop.
Save coreyhaines/8545bc5624d50bdae14c to your computer and use it in GitHub Desktop.
Type-based stack
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>());
@coreyhaines
Copy link
Author

I think I'm missing something, as this seems straight-forward to do. Internal dictionary of T -> Stack ?

@coreyhaines
Copy link
Author

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