linq - Dynamically pass Type to Method<T> -


i've method , retrieves me data according type passed in parameter, :

    protected void filllist<tentity>()     {         doworkfortentity();     } 

i need dynamically call method :

            type[] entities = system.reflection.assembly.getassembly(typeof(user)).gettypes();             type currententity = (from entity in entities                                   entity.name.equals(this.targetentity)                                   select entity).firstordefault();             filllist<currententity>(); 

i got error :

the type or namespace name 'currententity' not found (are missing using directive or assembly reference?)

i've tried intermediate object type, no success

any idea please ?

since there no information entity type in compile time, need construct , call appropriate method reflection:

type[] entities = system.reflection.assembly.getassembly(typeof(user)).gettypes(); type currententity = (from entity in entities                       entity.name.equals(this.targetentity)                       select entity).firstordefault();      var method = this.gettype().getmethod("filllist",  bindingflags.instance | bindingflags.nonpublic)                            .makegenericmethod(currententity); method.invoke(this, new object[0]); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -