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
This is not exactly what u are asking for. I find Jon's attribute method the best. But why not wrap it in an extension method?
public Type GetPowerupEffectType(this PowerupEffectType powerEffect)
{
switch (powerEffect)
{
case LIGHTNING:
return typeof(LightningPowerup);
case FIRE:
return typeof(FirePowerup);
case WATER:
return typeof(WaterPowerup);
default:
return default(Type);
}
}
And call it:
PowerupEffectType e = PowerupEffectType.WATER;
var t = e.GetPowerupEffectType();