title: How to pass a type to a generic type?
body: <p>I'm having some difficulties using generic types. We have a deserialize method which signature looks like this:</p>
  
  <pre><code>Public Function Deserialize(Of T)(ByVal compressedData As Byte()) As T
  </code></pre>
  
  <p>We have some binary data in database (which can be several types: type1.Question, type2.Question,...). So to prevent having to <code>Select case</code> in my loop, I tried something like this:</p>
  
  <pre><code>Dim questionType as Type = question.getType()
  Deserialize(Of questionType)(question)
  </code></pre>
  
  <p>This type is not recognized : "Type 'questionType' is not defined"</p>
  
  <p>Is there any way I can achieve this?</p>
  
  <p>I have read and tried <a href="https://stackoverflow.com/questions/1441063/how-do-i-create-something-of-a-variables-type">Suggestion 1</a> and <a href="https://stackoverflow.com/questions/232535/how-to-use-reflection-to-call-generic-method">Suggestion 2</a>, but for case 1, I cannot use type T as an expression and in case 2, I cannot use "Of type" as that gives in error in the code (the "type is not defined" one).</p>