Skip to content

Instantly share code, notes, and snippets.

@wallstop
Last active June 8, 2017 02:43
Show Gist options
  • Save wallstop/c242aac7df5dbfb55db1b742ac800f85 to your computer and use it in GitHub Desktop.
Save wallstop/c242aac7df5dbfb55db1b742ac800f85 to your computer and use it in GitHub Desktop.
class ItemFactory
{
public static Dictionary<Type, Func<AbstractItem>> Thing = new Dictionary<Type, Func<AbstractItem>>();
}
abstract class AbstractItem {
// Item common methods go here
}
class Item<T> : AbstractItem where T : Item<T> {
static Item() {
ItemFactory.Thing[typeof(T)] = () => (AbstractItem) Activator.CreateInstance(typeof(T));
}
}
class Boots : Item<Boots> {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment