fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4.  
  5. public enum AttackType
  6. {
  7. Melee,
  8. BlueBall,
  9. NightmareBall,
  10. Thunderstorm
  11. };
  12.  
  13. public struct Spell
  14. {
  15. public AttackType attackType;
  16. public double time;
  17. public double sliderSpeed;
  18. public int baseDmg;
  19.  
  20. public Spell(AttackType attackType, double time, double sliderSpeed, int baseDmg)
  21. {
  22. this.attackType = attackType;
  23. this.time = time;
  24. this.sliderSpeed = sliderSpeed;
  25. this.baseDmg = baseDmg;
  26. }
  27. }
  28.  
  29.  
  30. public class Test
  31. {
  32.  
  33. static T GetSpellProperty<T>(String name, Spell spell)
  34. {
  35. FieldInfo field = typeof(Spell).GetField(name);
  36. return (T)(field.GetValue(spell));
  37. }
  38.  
  39.  
  40. public static void Main()
  41. {
  42. List<Spell> knownSpells = new List<Spell>();
  43.  
  44. knownSpells.Add(new Spell(AttackType.Melee, 1.0f, 0.5f, 20));
  45. knownSpells.Add(new Spell(AttackType.BlueBall, 2.0f, 0.5f, 40));
  46. knownSpells.Add(new Spell(AttackType.NightmareBall, 4.0f, 0.5f, 50));
  47.  
  48. Console.WriteLine(GetSpellProperty<int>("baseDmg", knownSpells[0]));
  49. }
  50. }
Success #stdin #stdout 0.04s 23920KB
stdin
Standard input is empty
stdout
20