MemberInfo.MemberType Property

Definition

When overridden in a derived class, gets a MemberTypes value indicating the type of the member - method, constructor, event, and so on.

public abstract System.Reflection.MemberTypes MemberType { get; }

Property Value

A MemberTypes value indicating the type of member.

Implements

Examples

The following example displays the member name and type of a specified class.

using System;
using System.Reflection;

class Mymemberinfo
{
    public static int Main()
    {
        Console.WriteLine ("\nReflection.MemberInfo");

        // Get the Type and MemberInfo.
        Type MyType = Type.GetType("System.Reflection.PropertyInfo");
        MemberInfo[] Mymemberinfoarray = MyType.GetMembers();

        // Get the MemberType method and display the elements.
        Console.Write("\nThere are {0} members in ", Mymemberinfoarray.GetLength(0));
        Console.Write("{0}.", MyType.FullName);

        for (int counter = 0; counter < Mymemberinfoarray.Length; counter++)
        {
            Console.Write("\n" + counter + ". "
                + Mymemberinfoarray[counter].Name
                + " Member type - " +
                Mymemberinfoarray[counter].MemberType.ToString());
        }
        return 0;
    }
}

Remarks

This property is overridden in derived classes, and the override returns the appropriate member type. Therefore, when you examine a set of MemberInfo objects - for example, the array returned by GetMembers - the MemberType property can be used to determine the member type of any given member.

To get the MemberType property, get the class Type. From the Type, get the MethodInfo array. From the MethodInfo array, get the MemberTypes.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.5, 1.6, 2.0, 2.1

See also