C# program to print method names and its parameters using reflection classes
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to print method names and its parameters using reflection classes is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created two classes Sample and Program. Here, we imported the System.Reflection to use Assembly class.
The Program class contains the static method Main(), the Main() method is the entry point for the program.
Here, we created reference asm of assembly class which is initialized with object returned by the GetExecutingAssembly(), and then we get types from the current program assembly and got the name of classes that are created within the current program. After that, we got the name of methods created within the classes using the GetMethods() method of MethodInfo class and then got the name of parameters that are printed on the console screen.