mercredi 10 juillet 2019

Helper method for calling generic methods with reflection

Does anyone have a better way to do the following:

typeof(Service).GetMethod("UpdateData").MakeGenericMethod(dataType).Invoke(_myService, new object[]{ editData, metaData });

I'd love to do something like:

_myService.UpdateData<dataType>(editData, metaData);

But the <> accessor for generics will not take Type objects. I'm looking for a helper, utility, accessor, or something to make those generic method calls with reflection less cumbersome or at least centralized.





Aucun commentaire:

Enregistrer un commentaire