本文整理汇总了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