MethodInfo.MemberType-Eigenschaft
Ruft einen MemberTypes-Wert ab, der angibt, dass dieser Member eine Methode ist.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Overrides ReadOnly Property MemberType As MemberTypes
'Usage
Dim instance As MethodInfo
Dim value As MemberTypes
value = instance.MemberType
public override MemberTypes MemberType { get; }
public:
virtual property MemberTypes MemberType {
MemberTypes get () override;
}
/** @property */
public MemberTypes get_MemberType ()
public override function get MemberType () : MemberTypes
Eigenschaftenwert
Ein MemberTypes-Wert, der angibt, dass dieser Member eine Methode ist.
Hinweise
Diese Eigenschaft überschreibt MemberInfo.MemberType. Wenn Sie daher eine Gruppe von MemberInfo-Objekten überprüfen, z. B. das von GetMembers zurückgegebene Array, gibt die MemberType-Eigenschaft nur dann MemberTypes.Method zurück, wenn ein bestimmter Member eine Methode ist.
Wenn Sie die MemberType-Eigenschaft abrufen möchten, rufen Sie zunächst den Type der Klasse ab. Über Type rufen Sie MethodInfo ab. Über MethodInfo rufen Sie MemberType ab.
Beispiel
Im folgenden Beispiel wird der Typ des angegebenen Members angezeigt.
Imports System
Imports System.Reflection
Class MyMethodInfo
Public Shared Function Main() As Integer
Console.WriteLine("Reflection.MethodInfo")
' Get the Type and MethodInfo.
Dim MyType As Type = Type.GetType("System.Reflection.FieldInfo")
Dim Mymethodinfo As MethodInfo = MyType.GetMethod("GetValue")
Console.WriteLine(MyType.FullName + "." + Mymethodinfo.Name)
' Get and display the MemberType property.
Dim Mymembertypes As MemberTypes = Mymethodinfo.MemberType
If MemberTypes.Constructor = Mymembertypes Then
Console.WriteLine("MemberType is of type All.")
ElseIf MemberTypes.Custom = Mymembertypes Then
Console.WriteLine("MemberType is of type Custom.")
ElseIf MemberTypes.Event = Mymembertypes Then
Console.WriteLine("MemberType is of type Event.")
ElseIf MemberTypes.Field = Mymembertypes Then
Console.WriteLine("MemberType is of type Field.")
ElseIf MemberTypes.Method = Mymembertypes Then
Console.WriteLine("MemberType is of type Method.")
ElseIf MemberTypes.Property = Mymembertypes Then
Console.WriteLine("MemberType is of type Property.")
ElseIf MemberTypes.TypeInfo = Mymembertypes Then
Console.WriteLine("MemberType is of type TypeInfo.")
End If
Return 0
End Function
End Class
using System;
using System.Reflection;
class MyMethodInfo
{
public static int Main()
{
Console.WriteLine("Reflection.MethodInfo");
// Get the Type and MethodInfo.
Type MyType = Type.GetType("System.Reflection.FieldInfo");
MethodInfo Mymethodinfo = MyType.GetMethod("GetValue");
Console.WriteLine(MyType.FullName + "." + Mymethodinfo.Name);
// Get and display the MemberType property.
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;
}
}
using namespace System;
using namespace System::Reflection;
int main()
{
Console::WriteLine( "Reflection.MethodInfo" );
// Get the Type and MethodInfo.
Type^ MyType = Type::GetType( "System.Reflection.FieldInfo" );
MethodInfo^ Mymethodinfo = MyType->GetMethod( "GetValue" );
Console::WriteLine( "{0}.{1}", MyType->FullName, Mymethodinfo->Name );
// Get and display the MemberType property.
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;
}
import System.*;
import System.Reflection.*;
class MyMethodInfo
{
public static void main(String[] args)
{
Console.WriteLine("Reflection.MethodInfo");
// Get the Type and MethodInfo.
Type myType = Type.GetType("System.Reflection.FieldInfo");
MethodInfo myMethodInfo = myType.GetMethod("GetValue");
Console.WriteLine((myType.get_FullName() + "."
+ myMethodInfo.get_Name()));
// Get and display the MemberType property.
MemberTypes myMemberTypes = myMethodInfo.get_MemberType();
if (MemberTypes.Constructor.Equals(myMemberTypes)) {
Console.WriteLine("MemberType is of type All.");
}
else {
if (MemberTypes.Custom.Equals(myMemberTypes)) {
Console.WriteLine("MemberType is of type Custom.");
}
else {
if ( MemberTypes.Event.Equals(myMemberTypes)) {
Console.WriteLine("MemberType is of type Event.");
}
else {
if ( MemberTypes.Field.Equals(myMemberTypes)) {
Console.WriteLine("MemberType is of type Field.");
}
else {
if ( MemberTypes.Method.Equals(myMemberTypes)) {
Console.WriteLine("MemberType is of type Method.");
}
else {
if ( MemberTypes.Property.Equals(myMemberTypes)) {
Console.WriteLine(
"MemberType is of type Property.");
}
else {
if ( MemberTypes.TypeInfo.Equals
(myMemberTypes)) {
Console.WriteLine
("MemberType is of type TypeInfo.");
}
}
}
}
}
}
}
} //main
} //MyMethodInfo
import System;
import System.Reflection;
class MyMethodInfo
{
public static function Main() : void
{
Console.WriteLine("Reflection.MethodInfo");
//Get the Type and MethodInfo.
var MyType : Type = Type.GetType("System.Reflection.FieldInfo");
var Mymethodinfo : MethodInfo = MyType.GetMethod("GetValue");
Console.WriteLine(MyType.FullName + "." + Mymethodinfo.Name);
//Get and display the MemberType property.
var Mymembertypes : MemberTypes = 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" );
}
}
}
MyMethodInfo.Main();
/*
This code produces the following output:
Reflection.MethodInfo
System.Reflection.FieldInfo.GetValue
MemberType is of type Method
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
MethodInfo-Klasse
MethodInfo-Member
System.Reflection-Namespace