MethodBase.IsFinal Property
Gets a value indicating whether this method is final.
Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)
To determine if a method is overridable, it is not sufficient to check that IsVirtual is true. For a method to be overridable, IsVirtual must be true and IsFinal must be false. For example, a method might be non-virtual, but it implements an interface method. The common language runtime requires that all methods that implement interface members must be marked as virtual; therefore, the compiler marks the method virtual final. So there are cases where a method is marked as virtual but is still not overridable.
To establish with certainty whether a method is overridable, use code such as this:
if (MethodInfo.IsVirtual && !MethodInfo.IsFinal)
If IsVirtual is false or IsFinal is true, then the method cannot be overridden.
The following example displays false for IsFinal, which might lead you to think that MyMethod is overridable. The code prints false even though MyMethod is not marked virtual and thus cannot be overridden.
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); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.