MethodBase.IsAbstract Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nilai yang menunjukkan apakah metodenya abstrak.
public:
property bool IsAbstract { bool get(); };
public bool IsAbstract { get; }
member this.IsAbstract : bool
Public ReadOnly Property IsAbstract As Boolean
Nilai Properti
true
jika metodenya abstrak; jika tidak, false
.
Penerapan
Contoh
Contoh berikut menentukan apakah metode yang ditentukan abstrak dan menampilkan hasilnya.
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;
}
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;
}
}
Imports System.Reflection
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
Keterangan
Anggota abstrak dinyatakan pada kelas dasar dan tidak memiliki implementasi yang disediakan.
Untuk mendapatkan MethodBase, pertama-tama dapatkan jenisnya. Dari jenis , dapatkan metode . Dari metode , dapatkan MethodBase
.
MethodBase
Jika konstruktor atau selain publik, konstruktor dilindungi dan tidak dapat diakses dengan mudah. Untuk mengakses metode non-publik, atur BindingFlags masker ke NonPublic
di GetMethod
.