System.Reflection.MethodBase Class

Namespace

System.Reflection

Assembly

System.Private.CoreLib.dll

Summary

Represents methods and constructors. This abstract class provides information about method signatures, calling conventions, custom attributes, and security information.

Syntax

public abstract class MethodBase : MemberInfo

Inheritance

Object → MemberInfo → MethodBase

Members

MemberTypeDescription
IsPublicboolGets a value indicating whether the method is public.
IsStaticboolGets a value indicating whether the method is static.
InvokeobjectInvokes the method or constructor represented by this instance.
GetCustomAttributesobject[]Returns an array of custom attributes applied to this method.
GetParametersParameterInfo[]Returns the parameters of the method.

Remarks

The MethodBase class provides a base for MethodInfo (which represents methods) and ConstructorInfo (which represents constructors). It enables inspection of method metadata at runtime, which is essential for scenarios such as dynamic type generation, serialization, and custom attribute processing.

Example

// Display the names of all public instance methods of a type
using System;
using System.Reflection;

class Demo
{
    static void Main()
    {
        Type t = typeof(String);
        MethodBase[] methods = t.GetMethods(BindingFlags.Public | BindingFlags.Instance);
        foreach (MethodBase mb in methods)
        {
            Console.WriteLine($"{mb.ReturnType?.Name ?? "void"} {mb.Name}");
        }
    }
}