title: How can I create a data structure containing properties whose types are defined at runtime
body: <p>I am working on a data visualisation tool. It retrieves a bunch of data from a plain text file and then draws various charts and graphs of that data.</p>
  
  <p>So far I have been working with one set of data of which I know the types.</p>
  
  <p>For example if I'm working with a CSV file that looks like this:</p>
  
  <p>id, username, number of messages, message <br>
  23123124, @SomeUsername, 5, This 1s a 5tr1ng<br>
  89134349, @AnotherUsername, 8, Another string</p>
  
  <p>Then I can store this in an object like this:</p>
  
  <pre><code>public class SomeClass
  {
      private string id;
      private string username;
      private int numberOfMessages;
      private string message;
  }
  </code></pre>
  
  <p>Then I just have a <code>List&lt;SomeClass&gt;</code>.</p>
  
  <p>That's great and everything, but it will only work with that particular CSV file. I want to have a data structure that can be flexible, depending on the contents of the CSV file.</p>
  
  <p>The number of properties and the names of those properties is easily discovered by reading the header row in the first line of the text file. What type each piece of data is isn't clear (e.g. an id could be stored as an int or a string), so I'm going to ask the user to tell the application what type to use for each property. I could do this by displaying the name of each property next to a dropdown with options of string, int, bool etc.</p>
  
  <p>But how do I take that user input and create a data structure that contains properties of those types. So if the user goes through a form with 3 drop downs and selects "String", "Integer" and "Boolean", I effectively want an object that looks like this:</p>
  
  <pre><code>public class SomeClass
  {
      private string someString;
      private int someInt;
      private bool someBool;
  }
  </code></pre>
  
  <p>What is the best way of achieving this? I have a reasonable understanding of <strong>Generics</strong> but not sure how to use them in this case. I have heard of <strong>Reflection</strong>, the <strong>Type</strong> class and the <strong>dynamic</strong> keyword but don't really understand them. I have tried using Dictionaries but keep getting stuck. Are any of these options viable? Are they overkill? Am I overthinking this? <strong>HELP ME PLEASE!</strong> :D</p>
  
  <p>Thank you!</p>