This documentation is archived and is not being maintained.

MethodBase.IsAbstract Property

Gets a value indicating whether the method is abstract.

[Visual Basic]
Public ReadOnly Property IsAbstract As Boolean
[C#]
public bool IsAbstract {get;}
[C++]
public: __property bool get_IsAbstract();
[JScript]
public function get IsAbstract() : Boolean;

Property Value

true if the method is abstract; otherwise, false.

Remarks

An abstract member is declared on a base class and has no implementation supplied.

To get the MethodBase, first get the type. From the type, get the method. From the method, get the MethodBase. If the MethodBase or constructor is other than public, it is protected and cannot be readily accessed. To access a non-public method, set the BindingFlags mask to NonPublic in GetMethod.

Example

The following example determines whether specified the method is abstract and displays the result.

[Visual Basic] 
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

[C#] 
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;
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;

int main()
{      
    Console::WriteLine (S"\nReflection.MethodBase");

    // Get the types.
    Type* MyType1 = Type::GetType(S"System.Runtime.Serialization.Formatter");       
    Type* MyType2 = Type::GetType(S"System.Reflection.MethodBase");

    // Get and display the methods.
    MethodBase* Mymethodbase1 = 
        MyType1->GetMethod(S"WriteInt32",
            static_cast<BindingFlags>(BindingFlags::NonPublic|BindingFlags::Instance));

    MethodBase* Mymethodbase2 = 
        MyType2->GetMethod(S"GetCurrentMethod",
            static_cast<BindingFlags>(BindingFlags::Public|BindingFlags::Static));

    Console::Write(S"\nMymethodbase = {0}", Mymethodbase1);
    if (Mymethodbase1->IsAbstract)
        Console::Write (S"\nMymethodbase is an abstract method.");
    else
        Console::Write (S"\nMymethodbase is not an abstract method.");

    Console::Write(S"\n\nMymethodbase = {0}", Mymethodbase2);
    if (Mymethodbase2->IsAbstract)
        Console::Write (S"\nMymethodbase is an abstract method.");
    else
        Console::Write (S"\nMymethodbase is not an abstract method.");

    return 0;
}

[JScript] 
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
*/

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

MethodBase Class | MethodBase Members | System.Reflection Namespace | Boolean | BindingFlags

Show: