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
Post a Comment