So, I am creating a game in XNA, C # 4.0, and I need to manage a lot of PowerUps (which in the code all inherit from the PowerUp class), and to control the internal management of PowerUps, I currently have enum, PowerupEffectType, with a value for each child PowerUp class. In the end, in the code, I need to make the conversion from PowerupEffectType to the Powerup type (of the Type class, achieved usually with typeof([class name]) ).
Since this is a group project, I want to marry each PowerupEffectType value to its corresponding class type, and also, possibly: i.e. not just expect my other programmers to use switch statements to do the conversion manually, and make sure that add-ons / extensions in the future assume as few changes as possible in as many places as possible. I have several options for this, and the best I've discovered so far is to create pseudo-enum methods that condense all up to one switch statement (99% of what I want), thanks to some tips that I found here : http://msdn.microsoft.com/en-us/library/bb383974.aspx
But I'm trying to do it one more step - can I save Type in enum ? I know that you can save enums as a specific type (link: http://msdn.microsoft.com/en-us/library/cc138362.aspx ), but Type not one of them. The current selections are byte, sbyte, short, ushort, int, uint, long and ulong. Is there a possible way to save a Type conversion to any of the above data types and vice versa?
Just to be clear, this is what I WISH I could do, and I'm looking for a way to do:
// (Assuming 'LightningPowerup', 'FirePowerup', and 'WaterPowerup' are // all declared classes that inherit from a single base class) public enum PowerupEffectType { LIGHTNING = typeof(LightningPowerup), FIRE = typeof(FirePowerup), WATER = typeof(WaterPowerup) }
Is there a way to do this, or am I just overdoing the solution to a problem that is already 99% complete?
Thanks in advance!
enums c # types type-conversion
KeithA45 Jun 13 2018-12-12T00: 00Z
source share