本文整理匯總了C#中System.Reflection.MethodBase.IsVirtual屬性的典型用法代碼示例。如果您正苦於以下問題:C# MethodBase.IsVirtual屬性的具體用法?C# MethodBase.IsVirtual怎麽用?C# MethodBase.IsVirtual使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。
在下文中一共展示了MethodBase.IsVirtual屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MyMethod
//引入命名空間
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);
}
}
示例2: IsOverride
//引入命名空間
using System;
using System.Reflection;
public class ReflectionUtilities
{
public static bool IsOverride(MethodInfo method)
{
return ! method.Equals(method.GetBaseDefinition());
}
}
public class Example
{
public static void Main()
{
MethodInfo equals = typeof(Int32).GetMethod("Equals",
new Type[] { typeof(Object) } );
Console.WriteLine("{0}.{1} is inherited: {2}",
equals.ReflectedType.Name, equals.Name,
ReflectionUtilities.IsOverride(equals));
equals = typeof(Object).GetMethod("Equals",
new Type[] { typeof(Object) } );
Console.WriteLine("{0}.{1} is inherited: {2}",
equals.ReflectedType.Name, equals.Name,
ReflectionUtilities.IsOverride(equals));
}
}
輸出:
Int32.Equals is inherited: True Object.Equals is inherited: False