title: Is there a way to access a class's members where when acessing you use a string instead of class name
body: <p><strong>Im looking to use some reflection to access all the members in a class and get their values.</strong> This is the class's. I always initialize the "Championsids" class. (I know there is a lot of code but its quite straight forward). </p>
  
  <pre><code>        public class ChampionIds
          {
              public string type;
              public string format;
              public string version;
              public Data data;
          }
  
          public class Data
          {
              public Champions Aatrox;
              public Champions Ahri;
              public Champions Akali;
              public Champions Alistar;
              public Champions Amumu;
              public Champions Anivia;
              public Champions Annie;
              public Champions Ashe;
              public Champions AurelionSol;
              public Champions Azir;
              public Champions Bard;
              public Champions Blitzcrank;
              public Champions Brand;
              public Champions Braum;
              public Champions Caitlyn;
              public Champions Camille;
              public Champions Cassiopeia;
              public Champions Chogath;
              public Champions Corki;
              public Champions Darius;
              public Champions Diana;
              public Champions Draven;
              public Champions DrMundo;
              public Champions Ekko;
              public Champions Elise;
              public Champions Evelynn;
              public Champions Ezreal;
              public Champions FiddleSticks;
              public Champions Fiora;
              public Champions Fizz;
              public Champions Galio;
              public Champions Gangplank;
              public Champions Garen;
              public Champions Gnar;
              public Champions Gragas;
              public Champions Graves;
              public Champions Hecarim;
              public Champions Heimerdinger;
              public Champions Illaoi;
              public Champions Irelia;
              public Champions Ivern;
              public Champions Janna;
              public Champions JarvanIV;
              public Champions Jax;
              public Champions Jayce;
              public Champions Jhin;
              public Champions Jinx;
              public Champions Kalista;
              public Champions Karma;
              public Champions Karthus;
              public Champions Kassadin;
              public Champions Katarina;
              public Champions Kayle;
              public Champions Kennen;
              public Champions Khazix;
              public Champions Kindred;
              public Champions Kled;
              public Champions KogMaw;
              public Champions Leblanc;
              public Champions LeeSin;
              public Champions Leona;
              public Champions Lissandra;
              public Champions Lucian;
              public Champions Lulu;
              public Champions Lux;
              public Champions Malphite;
              public Champions Malzahar;
              public Champions Maokai;
              public Champions MasterYi;
              public Champions MissFortune;
              public Champions MonkeyKing;
              public Champions Mordekaiser;
              public Champions Morgana;
              public Champions Nami;
              public Champions Nasus;
              public Champions Nautilus;
              public Champions Nidalee;
              public Champions Nocturne;
              public Champions Nunu;
              public Champions Olaf;
              public Champions Orianna;
              public Champions Pantheon;
              public Champions Poppy;
              public Champions Quinn;
              public Champions Rammus;
              public Champions RekSai;
              public Champions Renekton;
              public Champions Rengar;
              public Champions Riven;
              public Champions Rumble;
              public Champions Ryze;
              public Champions Sejuani;
              public Champions Shaco;
              public Champions Shen;
              public Champions Shyvana;
              public Champions Singed;
              public Champions Sion;
              public Champions Sivir;
              public Champions Skarner;
              public Champions Sona;
              public Champions Soraka;
              public Champions Swain;
              public Champions Syndra;
              public Champions TahmKench;
              public Champions Taliyah;
              public Champions Talon;
              public Champions Taric;
              public Champions Teemo;
              public Champions Thresh;
              public Champions Tristana;
              public Champions Trundle;
              public Champions Tryndamere;
              public Champions TwistedFate;
              public Champions Twitch;
              public Champions Udyr;
              public Champions Urgot;
              public Champions Varus;
              public Champions Vayne;
              public Champions Veigar;
              public Champions Velkoz;
              public Champions Vi;
              public Champions Viktor;
              public Champions Vladimir;
              public Champions Volibear;
              public Champions Warwick;
              public Champions Xerath;
              public Champions XinZhao;
              public Champions Yasuo;
              public Champions Yorick;
              public Champions Zac;
              public Champions Zed;
              public Champions Ziggs;
              public Champions Zilean;
              public Champions Zyra;
          }
  
          public class Champions
          {
              public string version;
              public string id;
              public string key;
              public string name;
              public string title;
              public string blurb;
              public Dictionary&lt;string, int&gt; info;
              public Dictionary&lt;string, string&gt; image;
              public List&lt;string&gt; tags;
              public string partype;
              public Dictionary&lt;string, double&gt; stats;
          }
  </code></pre>
  
  <p>When i initialize it values are automatically assigned to all the members. That all works fine</p>
  
  <pre><code>ChampionIds championIds = JsonConvert.DeserializeObject&lt;ChampionIds&gt;(json2); //Assignment works perfect!
  </code></pre>
  
  <p>And now i can access all the values as so. Just for an example of usage</p>
  
  <pre><code>Console.WriteLine(championIds.data.Aatrox.id);
  Console.WriteLine(championIds.data.Aatrox.key);
  
  Console.WriteLine(championIds.data.AurelionSol.version);
  Console.WriteLine(championIds.data.AurelionSol.title);
  </code></pre>
  
  <p>But the problem is i want to get all the different champions <strong>keys</strong> and <strong>names</strong> into a Dictionary. So something like this.</p>
  
  <pre><code>Dictionary&lt;string, string&gt; ChampIdDict = new Dictionary&lt;string, string&gt;();
  ChampIdDict.Add(championIds.data.Aatrox.key, championIds.data.Aatrox.name);
  </code></pre>
  
  <p>And i want to do this for each champion. For an example like this</p>
  
  <pre><code>Dictionary&lt;string, string&gt; ChampIdDict = new Dictionary&lt;string, string&gt;();
  ChampIdDict.Add(championIds.data.Aatrox.key, championIds.data.Aatrox.name);
  ChampIdDict.Add(championIds.data.Ahri.key, championIds.data.Ahri.name);
  ChampIdDict.Add(championIds.data.Akali.key, championIds.data.Akali.name);
  //and so on
  </code></pre>
  
  <p>But i dont want to make 100 lines in my code of this way. So i iterate through all members and get their names easily with this code</p>
  
  <pre><code>FieldInfo[] fields = typeof(Data).GetFields();
  foreach (var field in fields)
  {
       Console.WriteLine(field.Name);
  }
  </code></pre>
  
  <p>And the result is this</p>
  
  <pre><code>Aatrox
  Ahri
  Akali
  Alistar
  Amumu
  Anivia
  //and so on
  </code></pre>
  
  <p>How do i make it so i can do this</p>
  
  <pre><code>FieldInfo[] fields = typeof(Data).GetFields();
  foreach (var field in fields)
  {
      Console.WriteLine("Inserting champion = " + field.Name + " into the dictionary");
      string key = championIds.data.(field.Name).key;
      string name = championIds.data.(field.Name).name;
      ChampIdDict.Add(key, name)
  }
  </code></pre>
  
  <p>The result is that i simple get the champion id from a website and i say
  string returnedChampionId = //from website ex. 266
  string championName = ChampIdDict["266"];</p>
  
  <p>Thanks for reading. Hope you can recommend something</p>