Export (0) Print
Expand All

MethodBase.IsAbstract Property

Gets a value indicating whether the method is abstract.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public bool IsAbstract { get; }
/** @property */
public final boolean get_IsAbstract ()

public final function get IsAbstract () : boolean

Property Value

true if the method is abstract; otherwise, false.

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.

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

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;
    }
}

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
*/

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft