title: Calling a generic function with a type parameter determined at runtime
body: <p>I have a question involving calling a class's generic method with a type parameter that is known at runtime.</p>
  
  <p>In specific, the code looks like so:</p>
  
  <pre><code>
  FieldInfo[] dataFields = this.GetType().GetFields( BindingFlags.Public | BindingFlags.Instance );
  
  // data is just a byte array used internally in DataStream
  DataStream ds = new DataStream( data );
  
  foreach ( FieldInfo field in dataFields )
  {
      Type fieldType = field.FieldType;
  
      // I want to call this method and pass in the type parameter specified by the field's type
      object objData = ( object ) ds.Read&lt;fieldType&gt;();
  }
  </code></pre>
  
  <p>The Read() function looks like so:</p>
  
  <pre><code>
  public T Read() where T : struct
  </code></pre>
  
  <p>This function's purpose is to return data read from a byte array.</p>
  
  <p>Is there any way to call a generic method at runtime like this?</p>