lundi 8 avril 2019

Using a Dynamic Type for a Generic Function

Here is a simple exemple of a generic function :

public void DoSomething<T>() { /*... */  }

Now, let's say I manage to get a dynamic type using reflection. If I want to pass it as T in DoSomething(), I would like to do something just like this :

Type myType = typeFound;
DoSomething<myType>();

Problem is, it isn't expecting a variable thus giving me an error.

How would you do that ?





Aucun commentaire:

Enregistrer un commentaire