C# MethodInfo MemberType

Description

MethodInfo MemberType Gets a MemberTypes value indicating that this member is a method.

Syntax

MethodInfo.MemberType has the following syntax.


public override MemberTypes MemberType { get; }

Example


using System;//w  w w.j  a v  a  2s  .  c om
using System.Reflection;

class MyMethodInfo
{
    public static int Main()
    {
        Type MyType = Type.GetType("System.Reflection.FieldInfo");
        MethodInfo Mymethodinfo = MyType.GetMethod("GetValue");
        Console.WriteLine(MyType.FullName + "." + Mymethodinfo.Name);

        MemberTypes Mymembertypes = Mymethodinfo.MemberType;
        if (MemberTypes.Constructor == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type All.");
        }
        else if (MemberTypes.Custom == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Custom.");
        }
        else if (MemberTypes.Event == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Event.");
        }
        else if (MemberTypes.Field == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Field.");
        }
        else if (MemberTypes.Method == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Method.");
        }
        else if (MemberTypes.Property == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type Property.");
        }
        else if (MemberTypes.TypeInfo == Mymembertypes)
        {
            Console.WriteLine("MemberType is of type TypeInfo.");
        }

        return 0;
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo