Skip to content

Instantly share code, notes, and snippets.

@jwill9999
Last active December 9, 2018 17:10
Show Gist options
  • Save jwill9999/8bc08aaf98a5d3de2b0992e0e2abccfa to your computer and use it in GitHub Desktop.
Save jwill9999/8bc08aaf98a5d3de2b0992e0e2abccfa to your computer and use it in GitHub Desktop.
c# Dump function - reflection GetMethods
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