MethodBase.IsFinal プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)


メソッドがオーバーライドできるかどうかを判断するには、IsVirtual が true であることを確認するだけでは不十分です。オーバーライドできるメソッドは、IsVirtual が true で、IsFinal が false である必要があります。たとえば、メソッドが非仮想で、インターフェイス メソッドを実装している場合があります。共通言語ランタイムでは、インターフェイス メンバを実装するすべてのメソッドは virtual としてマークする必要があるため、コンパイラはメソッドを virtual final としてマークします。したがって、メソッドが virtual としてマークされていても、オーバーライドできない場合もあります。
メソッドがオーバーライドできるかどうかを確実に判断するには、次のようなコードを使用します。
if (MethodInfo.IsVirtual && !MethodInfo.IsFinal)

この例を実行すると、IsFinal の値として false が出力されるため、MyMethod をオーバーライド可能と見なしがちです。MyMethod が virtual としてマークされていなくても、このコードは false を出力するため、MyMethod をオーバーライドすることはできません。
Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class MyClass1 Public Sub MyMethod() End Sub Public Shared Sub Main() Dim m As MethodBase = GetType(MyClass1).GetMethod("MyMethod") Console.WriteLine("The IsFinal property value of MyMethod is {0}.", m.IsFinal) Console.WriteLine("The IsVirtual property value of MyMethod is {0}.", m.IsVirtual) End Sub End Class
using System; using System.Reflection; public class MyClass { public void MyMethod() { } public static void Main() { MethodBase m = typeof(MyClass).GetMethod("MyMethod"); Console.WriteLine("The IsFinal property value of MyMethod is {0}." , m.IsFinal); Console.WriteLine("The IsVirtual property value of MyMethod is {0}." , m.IsVirtual); } }
using namespace System; using namespace System::Reflection; public ref class MyClass { public: void MyMethod(){} }; int main() { MethodBase^ m = MyClass::typeid->GetMethod( "MyMethod" ); Console::WriteLine( "The IsFinal property value of MyMethod is {0}.", m->IsFinal ); Console::WriteLine( "The IsVirtual property value of MyMethod is {0}.", m->IsVirtual ); }
import System.*; import System.Reflection.*; public class MyClass { public void MyMethod() { } //MyMethod public static void main(String[] args) { MethodBase m = MyClass.class.ToType().GetMethod("MyMethod"); Console.WriteLine("The IsFinal property value of MyMethod is {0}." , System.Convert.ToString( m.get_IsFinal())); Console.WriteLine("The IsVirtual property value of MyMethod is {0}." , System.Convert.ToString( m.get_IsVirtual())); } //main } //MyClass

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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


_MethodBase.IsFinal プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- MethodBase.IsFinalのページへのリンク