Skip to content

Instantly share code, notes, and snippets.

@jwill9999
Created December 9, 2018 17:17
Show Gist options
  • Save jwill9999/eca1579023d86d8bb82dbd84ad42bac5 to your computer and use it in GitHub Desktop.
Save jwill9999/eca1579023d86d8bb82dbd84ad42bac5 to your computer and use it in GitHub Desktop.
C# Dump Class Methods - reflection GetMembers
using System;
using System.Linq;
using System.Reflection;
namespace Print
{
class Program
{
static void Main(string[] args)
{
Type mytype = (typeof(MyTypeClass));
MethodInfo[] myArrayMethodInfo = mytype.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
System.Console.WriteLine(myArrayMethodInfo.Length);
ShowMethods(myArrayMethodInfo);
MyTypeClass myObject = new MyTypeClass();
MemberInfo[] myMemberInfo;
Type myType = myObject.GetType();
myMemberInfo = myType.GetMembers();
Console.WriteLine("\nThe members of class '{0}' are :\n", myType);
ShowMethods(myMemberInfo);
}
static void ShowMethods(MemberInfo[] myMemberInfo)
{
for (int i = 0; i < myMemberInfo.Length; i++)
{
// Display name and type of the concerned member.
Console.WriteLine("'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType);
}
}
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