c# - Convert system.Type to user defined type -


i trying classes inheriting base class.

  public void getclassnames()   {       list<baseclass> data = appdomain.currentdomain.getassemblies()                            .selectmany(assembly => assembly.gettypes())                            .where(type => type != null &&                             type.issubclassof(typeof(baseclass))).tolist();   } 

however, above code throws error.
"cannot implicitly convert type system.collections.generic.list<system.type>' tosystem.collections.generic.list"

how cast type baseclass please?

you selecting types of assemblies sub-classes of baseclass. types not instances of types.

what want? method name getclassnames, maybe want:

public ienumnerable<string> getclassnames() {     list<string> baseclassnames = appdomain.currentdomain.getassemblies()        .selectmany(assembly => assembly.gettypes())        .where(type => type?.issubclassof(typeof(baseclass)) == true)        .select(type => type.fullname)        .tolist();     return baseclassnames; } 

if instead want types in assemblies derive baseclass:

public ienumnerable<type> getbaseclasssubtypesincurrrentassenblies() {     list<type> baseclasstypes = appdomain.currentdomain.getassemblies()        .selectmany(assembly => assembly.gettypes())        .where(type => type?.issubclassof(typeof(baseclass)) == true)        .tolist();     return baseclasstypes; } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -