title: Define struct dynamically in C#
body: <p>I am trying to define a struct dynamically in C#, based on a given input file with a list of member names and types.  For the sake of the question, assume the file has the following layout:</p>
  
  <pre><code>
  [Struct Name 1]
  parameter1, type1, typical_value1
  parameter2, type2
  parameter3, type1
  
  [Struct Name 2]
    ... etc
  </code></pre>
  
  <p>I have been reading through <a href="https://stackoverflow.com/questions/6187908/is-it-possible-to-dynamically-define-a-struct-in-c">this post</a> for some time now, and have not yet implemented it in C# -- my question is, can this be done?  Furthermore, can it be done without using <code>unsafe</code>?</p>
  
  <p>The reason I originally wanted to stick with using a struct is because I'm going to be using it to serialize a <code>byte[]</code> received via I/O, and the extension methods I have right now work perfectly for statically defined structs; however I would be open to rewriting it for a wrapper class to make it easier.</p>
  
  <p>The idea is that I would have one of several files that can be selected as a parsing source, based on what the user knows to be connected via I/O.  In other words, the file can be changed during runtime but only a single file can be selected at a time.</p>