title: Convert a struct to an object array
body: <p>I am reading in a binary file in to a struct with <code>StructLayout(LayoutKind.Explicit)</code> set. I need to move this data in to a DAO which has the structure of <code>Object[]</code>. Instead of manually typing each of the 40 or so fields that are in the struct I would just like to use reflection and convert all of the elements not starting with "Unknown". Here is what I have so far.</p>
  
  <pre><code>[StructLayout(LayoutKind.Explicit, CharSet=CharSet.Ansi)]
  struct ClientOld : IStuctToArray
  {
      [FieldOffset(0)]
      public byte Active;
  
      [FieldOffset(1)]
      [MarshalAs(UnmanagedType.AnsiBStr)]
      public string Title;
  
      [FieldOffset(10)]
      [MarshalAs(UnmanagedType.AnsiBStr)]
      public string LastName;
  
      [FieldOffset(36)]
      [MarshalAs(UnmanagedType.LPArray, SizeConst = 2)]
      public byte[] Unknown1;
  
      (...)
  
      [FieldOffset(368)]
      [MarshalAs(UnmanagedType.AnsiBStr)]
      public string AddedBy;
  
      [FieldOffset(372)]
      [MarshalAs(UnmanagedType.LPArray, SizeConst = 22)]
      public byte[] Unknown7;
  
      public object[] ToObjectArray()
      {
          return this.GetType().GetFields()
                     .Where(a =&gt; !a.Name.StartsWith("Unknown"))
                     .Select(b =&gt; /* This is where I am stuck */)
                     .ToArray();
      }
  }
  </code></pre>
  
  <p>I do not know what to put in the select area to get the value of my field. <code>b.GetValue</code> requires you to pass in a object and I do not know what object to pass. </p>
  
  <p>Any help would be greatly appreciated.</p>