Last active
December 9, 2018 17:10
-
-
Save jwill9999/8bc08aaf98a5d3de2b0992e0e2abccfa to your computer and use it in GitHub Desktop.
c# Dump function - reflection GetMethods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Dump { | |
class Program { | |
static void Main(string[] args) | |
{ | |
Type mytype = (typeof(MyTypeClass)); | |
// Get the public methods - bind the return types public etc | |
MethodInfo[] myArrayMethodInfo = mytype.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); | |
// Display the number of methods | |
System.Console.WriteLine(myArrayMethodInfo.Length); | |
// Display all the methods | |
ShowMethods(myArrayMethodInfo); | |
} | |
// Display information for all methods. | |
static void ShowMethods(MethodInfo[] myArrayMethodInfo) | |
{ | |
for (int i = 0; i < myArrayMethodInfo.Length; i++) | |
{ | |
MethodInfo myMethodInfo = (MethodInfo)myArrayMethodInfo[i]; | |
Console.WriteLine("\nThe name of the method is {0}.", myMethodInfo.Name); | |
} | |
} | |
} | |
public class MyTypeClass | |
{ | |
public void MyMethods() | |
{ | |
} | |
public int MyMethods1() | |
{ | |
return 3; | |
} | |
protected String MyMethods2() | |
{ | |
return "hello"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment