c# - Obtaining method signatures types and names -
i'm writing 'quick' c# application allow me see methods avaliable under assembly dll, far , can output class, access modifier , name :
private void btnlistmethodname() { string sassemblyfilename = assemblylocation.text; if (sassemblyfilename.length != 0) { assembly assem = assembly.loadfrom(sassemblyfilename); type[] types = assem.gettypes(); arraylist arrl = new arraylist(); foreach (type cls in types) { try { //add class name arrl.add(cls.fullname); if (cls.isabstract) arrl.add("abstract class:" + cls.name.tostring()); else if (cls.ispublic) arrl.add("public class:" + cls.name.tostring()); else if (cls.issealed) arrl.add("sealed class:" + cls.name.tostring()); memberinfo[] methodname = cls.getmethods(); foreach (memberinfo method in methodname) { method.reflectedtype.getproperties(); if (method.reflectedtype.ispublic) arrl.add("\tpublic - " + method.name.tostring()); else arrl.add("\tnon-public - " + method.name.tostring()); } } catch (system.nullreferenceexception) { console.writeline("error msg"); } } olvmain.setobjects(arrl); (int = 0; < arrl.count; i++) { assemblylist.items.add(arrl[i].tostring()); } } }
what need output datatype , name of methods signature values. example, @ moment output 'public - methodname' output 'public - methodname(string methoddata, int methoddata2)'
is possible?
you can obtain method's parameters this;
parameterinfo[] pars = method.getparameters();
to need change;
memberinfo[] methodname = cls.getmethods();
to
methodinfo[] methodname = cls.getmethods();
refer methodbase.getparameters
Comments
Post a Comment