using System; using System.Collections.Generic; using System.Reflection; public enum AttackType { Melee, BlueBall, NightmareBall, Thunderstorm }; public struct Spell { public AttackType attackType; public double time; public double sliderSpeed; public int baseDmg; public Spell(AttackType attackType, double time, double sliderSpeed, int baseDmg) { this.attackType = attackType; this.time = time; this.sliderSpeed = sliderSpeed; this.baseDmg = baseDmg; } } public class Test { static T GetSpellProperty(String name, Spell spell) { FieldInfo field = typeof(Spell).GetField(name); return (T)(field.GetValue(spell)); } public static void Main() { List knownSpells = new List(); knownSpells.Add(new Spell(AttackType.Melee, 1.0f, 0.5f, 20)); knownSpells.Add(new Spell(AttackType.BlueBall, 2.0f, 0.5f, 40)); knownSpells.Add(new Spell(AttackType.NightmareBall, 4.0f, 0.5f, 50)); Console.WriteLine(GetSpellProperty("baseDmg", knownSpells[0])); } }