So I\'m creating a game in XNA, C# 4.0, and I need to manage a lot of PowerUps (which in code are all inherited from class \"PowerUp\"), and to handle back-end management of the
How about something like this?
You get the type-safety that you do with an enum, plus implicit conversion to Type
public class PowerupEffectType
{
private readonly Type _powerupType;
public static implicit operator Type(PowerupEffectType powerupEffectType)
{
return powerupEffectType._powerupType;
}
private PowerupEffectType(Type powerupType)
{
_powerupType = powerupType;
}
public static readonly PowerupEffectType LIGHTNING = new PowerupEffectType(typeof(LightningPowerup));
public static readonly PowerupEffectType FIRE = new PowerupEffectType(typeof(FirePowerup));
public static readonly PowerupEffectType WATER = new PowerupEffectType(typeof(WaterPowerup));
}