Object - GetMethods

A T extension method that returns all the public methods of the current Type.

Try it

public static void Main()
{
	//C# Extension Method: Object - GetMethods
    var methods = typeof(MethodModel<int>).GetMethods();
	
	foreach(var method in methods)
	{
		Console.WriteLine(method.GetDeclaraction());
	}
}

public class MethodModel<T> : AbstractMethodModel
{
    public class Toto<T2> {}
    public static int StaticMethod() { return 1; }
    public override int OverrideMethod() { return 1; }
    public virtual int VirtualMethod() { return 1; }
    public int PublicMethod() { return 1; }
    private int PrivateMethod() { return 1; }
    internal int InternalMethod() { return 1; }
    protected int ProtectedMethod() { return 1; }
    protected internal int ProtectedInternalMethod() { return 1; }
    public int OutParameterMethod(out int i)
    {
        i = 1;
        return 1;
    }
    public int RefParameterMethod(ref int i) { return 1; }
    public int ParamsParameterMethod(params int[] i) { return 1; }
    public int OptionalParameterMethod(int i = 1) { return 1; }
    public int InParameterModifierMethod([In] int i) { return 1; }
    public int OutParameterModifierMethod([Out] int i)
    {
        i = 1;
        return 1;
    }

    public int OptionalParameterModifierMethod([Optional] int i) { return 1; }

    public T GenericTypeMethod(T i) { return i; }

    public T1 GenericMethod<T1, T2>(T1 i, T2 i2) { return i; }
    public override int AbstractMethod()  { throw new NotImplementedException(); }
}

public abstract class AbstractMethodModel
{
    public abstract int AbstractMethod();
    public abstract int OverrideMethod();
}
}

public static class ExtensionMethodModel
{
public static int ExtensionParameterMethod(this int i)
{
    return 1;
}

View Source
using System.Reflection;

public static partial class Extensions
{
    /// <summary>
    ///     A T extension method that returns all the public methods of the current Type.
    /// </summary>
    /// <typeparam name="T">Generic type parameter.</typeparam>
    /// <param name="this">The @this to act on.</param>
    /// <returns>
    ///     An array of MethodInfo objects representing all the public methods defined for the current Type. or An empty
    ///     array of type MethodInfo, if no public methods are defined for the current Type.
    /// </returns>
    public static MethodInfo[] GetMethods<T>(this T @this)
    {
        return @this.GetType().GetMethods();
    }

    /// <summary>
    ///     A T extension method that searches for the methods defined for the current Type, using the specified binding
    ///     constraints.
    /// </summary>
    /// <typeparam name="T">Generic type parameter.</typeparam>
    /// <param name="this">The @this to act on.</param>
    /// <param name="bindingAttr">A bitmask comprised of one or more BindingFlags that specify how the search is conducted.</param>
    /// <returns>
    ///     An array of MethodInfo objects representing all methods defined for the current Type that match the specified
    ///     binding constraints. or An empty array of type MethodInfo, if no methods are defined for the current Type, or
    ///     if none of the defined methods match the binding constraints.
    /// </returns>
    public static MethodInfo[] GetMethods<T>(this T @this, BindingFlags bindingAttr)
    {
        return @this.GetType().GetMethods(bindingAttr);
    }
}