Get all the properties of a class, the name of the method

zhaozj2021-02-16  78

Use reflection: --------------------- namespace reflect {using system.reflection;

Public class classa {

Public static int main (string [] kami) {type t = typeof (test); console.writeline ("Type of class:" T); console.writeline ("Namespace:" T.NameSpace; constructorinfo [] Ci = T.Getconstructors (); console.writeline ("Constructors Are:"); Foreach (ConstructorInfo I I I IN CI) {Console.Writeline (i);} PropertyInfo [] PI = TGetProperties (); console.writeline "Properties Are:"); Foreach (PropertyInfo I in Pi) {Console.Writeline (i);} methodinfo [] mi = TgetMethods (); console.writeline ("Methods Are:"); Foreach (MethodInfo I in Mi) {Console.Writeline ("Name:" I.Name); parameterinfo [] PIF = i.getParameters (); foreach (parameterInfo p in pif) {console.writeline ("Type:" p.ParameterType " Parameter name: " p.Name);}}}}

PUBLIC CLASS TEST {INT i; int prop;

Public int prop {get {

Return Prop;

SET {Prop = Value;}

PUBLIC TEST () {} public test (int x) {i = x;}

Public int funca (int x) {console.writeline (x); return 2 * x;}}}}

转载请注明原文地址:https://www.9cbs.com/read-12284.html

New Post(0)