Last active
June 8, 2017 02:43
-
-
Save wallstop/c242aac7df5dbfb55db1b742ac800f85 to your computer and use it in GitHub Desktop.
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 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