Skip to content

Instantly share code, notes, and snippets.

@lggomez
Created April 4, 2017 19:57
Show Gist options
  • Save lggomez/80f6df7c53d18192561b3d2a484ba78e to your computer and use it in GitHub Desktop.
Save lggomez/80f6df7c53d18192561b3d2a484ba78e to your computer and use it in GitHub Desktop.
Get non System.Object methods from a given type parameter
private static List<MethodInfo> GetTypeMethods<T>()
{
List<MethodInfo> interfaceMethods = new List<MethodInfo>();
var targetType = typeof(T);
foreach (MethodInfo method in targetType.GetMethods() )
{
if (!method.IsSpecialName &&
!new List<string> { "tostring", "gethashcode", "equals", "gettype", "finalize", "memberwiseclone" }.Any(method.Name.ToLowerInvariant().Contains))
{
interfaceMethods.Add(method);
}
}
return interfaceMethods.GroupBy(_ => _.Name).Select(_ => _.First()).ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment