MethodBase.IsAbstract-Eigenschaft
Ruft einen Wert ab, der angibt, ob es sich um eine abstrakte Methode handelt.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public ReadOnly Property IsAbstract As Boolean
'Usage
Dim instance As MethodBase
Dim value As Boolean
value = instance.IsAbstract
public bool IsAbstract { get; }
public:
virtual property bool IsAbstract {
bool get () sealed;
}
/** @property */
public final boolean get_IsAbstract ()
public final function get IsAbstract () : boolean
Eigenschaftenwert
true, wenn die Methode abstrakt ist, andernfalls false.
Hinweise
Ein abstrakter Member ist für eine Basisklasse deklariert und verfügt über keine Implementierung.
Rufen Sie zuerst den Typ ab, um MethodBase abzurufen. Rufen Sie die Methode aus dem Typ ab. Rufen Sie MethodBase aus der Methode ab. Wenn MethodBase oder der Konstruktor nicht öffentlich sind, sind sie geschützt, und der Zugriff darauf ist nicht ohne weiteres möglich. Legen Sie die BindingFlags-Maske in GetMethod auf NonPublic fest, um auf eine nicht öffentliche Methode zugreifen zu können.
Beispiel
Im folgenden Beispiel wird bestimmt, ob die angegebene Methode abstrakt ist, und das Ergebnis wird angezeigt.
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class methodbase1
Public Shared Function Main() As Integer
Console.WriteLine("Reflection.MethodBase")
Console.WriteLine()
' Get the types.
Dim MyType1 As Type = _
Type.GetType("System.Runtime.Serialization.Formatter")
Dim MyType2 As Type = _
Type.GetType("System.Reflection.MethodBase")
' Get and display the methods
Dim Mymethodbase1 As MethodBase = _
MyType1.GetMethod("WriteInt32", BindingFlags.NonPublic Or BindingFlags.Instance)
Dim Mymethodbase2 As MethodBase = _
MyType2.GetMethod("GetCurrentMethod", BindingFlags.Public Or BindingFlags.Static)
Console.WriteLine("Mymethodbase = {0}", Mymethodbase1.ToString())
If Mymethodbase1.IsAbstract Then
Console.WriteLine(ControlChars.CrLf & "Mymethodbase is an abstract method.")
Else
Console.WriteLine(ControlChars.CrLf & "Mymethodbase is not an abstract method.")
End If
Console.Write("Mymethodbase = {0}", Mymethodbase2.ToString())
If Mymethodbase2.IsAbstract Then
Console.WriteLine(ControlChars.CrLf & "Mymethodbase is an abstract method.")
Else
Console.WriteLine(ControlChars.CrLf & "Mymethodbase is not an abstract method.")
End If
Return 0
End Function
End Class
using System;
using System.Reflection;
// using System.Windows.Forms;
class methodbase
{
public static int Main(string[] args)
{
Console.WriteLine ("\nReflection.MethodBase");
// Get the types.
Type MyType1 = Type.GetType("System.Runtime.Serialization.Formatter");
Type MyType2 = Type.GetType("System.Reflection.MethodBase");
// Get and display the methods.
MethodBase Mymethodbase1 =
MyType1.GetMethod("WriteInt32", BindingFlags.NonPublic|BindingFlags.Instance);
MethodBase Mymethodbase2 =
MyType2.GetMethod("GetCurrentMethod", BindingFlags.Public|BindingFlags.Static);
Console.Write("\nMymethodbase = " + Mymethodbase1.ToString());
if (Mymethodbase1.IsAbstract)
Console.Write ("\nMymethodbase is an abstract method.");
else
Console.Write ("\nMymethodbase is not an abstract method.");
Console.Write("\n\nMymethodbase = " + Mymethodbase2.ToString());
if (Mymethodbase2.IsAbstract)
Console.Write ("\nMymethodbase is an abstract method.");
else
Console.Write ("\nMymethodbase is not an abstract method.");
return 0;
}
}
using namespace System;
using namespace System::Reflection;
int main()
{
Console::WriteLine( "\nReflection.MethodBase" );
// Get the types.
Type^ MyType1 = Type::GetType( "System.Runtime.Serialization.Formatter" );
Type^ MyType2 = Type::GetType( "System.Reflection.MethodBase" );
// Get and display the methods.
MethodBase^ Mymethodbase1 = MyType1->GetMethod( "WriteInt32", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
MethodBase^ Mymethodbase2 = MyType2->GetMethod( "GetCurrentMethod", static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static) );
Console::Write( "\nMymethodbase = {0}", Mymethodbase1 );
if ( Mymethodbase1->IsAbstract )
Console::Write( "\nMymethodbase is an abstract method." );
else
Console::Write( "\nMymethodbase is not an abstract method." );
Console::Write( "\n\nMymethodbase = {0}", Mymethodbase2 );
if ( Mymethodbase2->IsAbstract )
Console::Write( "\nMymethodbase is an abstract method." );
else
Console::Write( "\nMymethodbase is not an abstract method." );
return 0;
}
import System.*;
import System.Reflection.*;
// import System.Windows.Forms;
class Methodbase
{
public static void main(String[] args)
{
Console.WriteLine("\nReflection.MethodBase");
// Get the types.
Type myType1 = Type.GetType("System.Runtime.Serialization.Formatter");
Type myType2 = Type.GetType("System.Reflection.MethodBase");
// Get and display the methods.
MethodBase myMethodBase1 =myType1.GetMethod("WriteInt32",
BindingFlags.NonPublic | BindingFlags.Instance);
MethodBase myMethodBase2 = myType2.GetMethod("GetCurrentMethod",
BindingFlags.Public | BindingFlags.Static);
Console.Write(("\nMymethodbase = " + myMethodBase1.ToString()));
if ( myMethodBase1.get_IsAbstract()) {
Console.Write("\nmyMethodBase is an abstract method.");
}
else {
Console.Write("\nmyMethodBase is not an abstract method.");
}
Console.Write(("\n\nmyMethodBase = " + myMethodBase2.ToString()));
if ( myMethodBase2.get_IsAbstract()) {
Console.Write("\nmyMethodBase is an abstract method.");
}
else {
Console.Write("\nmyMethodBase is not an abstract method.");
}
} //main
} //Methodbase
class methodbase
{
public static function Main() : int
{
Console.WriteLine ("\nReflection.MethodBase");
//Get the MethodBase of two methods.
//Get the types
var MyType1 : Type = Type.GetType("System.Runtime.Serialization.Formatter");
var MyType2 : Type = Type.GetType("System.Reflection.MethodBase");
//Get and display the methods
var Mymethodbase1 : MethodBase =
MyType1.GetMethod("WriteInt32", BindingFlags.Instance|BindingFlags.NonPublic);
var Mymethodbase2 : MethodBase =
MyType2.GetMethod("GetCurrentMethod", BindingFlags.Static|BindingFlags.Public);
Console.Write("\nMymethodbase = " + Mymethodbase1.ToString());
if (Mymethodbase1.IsAbstract)
Console.Write ("\nMymethodbase is an abstract method");
else
Console.Write ("\nMymethodbase is not an abstract method");
Console.Write("\n\nMymethodbase = " + Mymethodbase2.ToString());
if (Mymethodbase2.IsAbstract)
Console.Write ("\nMymethodbase is an abstract method");
else
Console.Write ("\nMymethodbase is not an abstract method");
}
}
methodbase.Main();
/*
Produces the following output
Reflection.MethodBase
Mymethodbase = Void WriteInt32 (Int32, System.String)
Mymethodbase is an abstract method
Mymethodbase = System.Reflection.MethodBase GetCurrentMethod ()
Mymethodbase is not an abstract 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
MethodBase-Klasse
MethodBase-Member
System.Reflection-Namespace
Boolean
BindingFlags-Enumeration