jeudi 13 avril 2017

Calling Service method using Reflection

This is what I would do in normal code

ServiceWrapper<myTypeService> svc = new ServiceWrapper<myTypeService>(param);   // trying to achieve this

However because "myType" will vary, I would like to do it by Reflection

I tried the following

Type IServiceType = System.Web.Compilation.BuildManager.GetType("myType" + "Service", true);    // this is ok
Type ServiceWrapperType = typeof(ServiceWrapper<>); 
Type ServiceWrapperClass = ServiceWrapperType.MakeGenericType(IServiceType);

How to tie them together?





Aucun commentaire:

Enregistrer un commentaire