title: Dynamically create a type for JsonSerializer.DeserializeAsync?
body: <p>I have method/Task where I would like to return a type which implementing some interface.
  I am choosing the type with lot of conditions and I have strong feeling, that it could be done simpler. Problem is, that I don't know how to choose type dynamically.</p>
  <p>This is OK:</p>
  <pre><code>IInterface Obj;
  //Type1 and Type2 implements IInterface
  if(true)
  {
      Obj = await JsonSerializer.DeserializeAsync&lt;Type1&gt;(memoryStream, JsonOpt);
      return Obj;
  }
  else
  {
      Obj = await JsonSerializer.DeserializeAsync&lt;Type2&gt;(memoryStream, JsonOpt);
      return Obj;
  }
  </code></pre>
  <p>This not:</p>
  <pre><code>IInterface Obj;
  Type type;
  //Type1 and Type2 implements IInterface
  if(true)
  {
      type = typeof(Type1);
  }
  else
  {
      type = typeof(Type2);
  }
  Obj = await JsonSerializer.DeserializeAsync&lt;type&gt;(memoryStream, JsonOpt);
  return Obj
  </code></pre>
  <p>I know I can use generics, but in the end of the day, the problem will be same. Here is some generic task.</p>
  <pre><code>    public class Test
      {
          public async Task&lt;T&gt; Ooo&lt;T&gt;() where T : new()
          {
              T t = new T();
              //something awaitable here
              return t;
          }
      }
  </code></pre>
  <p>here I have to decide the type:</p>
  <pre><code>        Test test = new();
          Type t;
          if (true)
          {
              t = typeof(TimeZoneInfo);
          }
          else
          {
              t = typeof(TimeZone);
          }
          object obj = await test.Ooo&lt;typeof(t)&gt;();
  </code></pre>