本文整理汇总了C#中System.Reflection.MethodBase.IsHideBySig属性的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.IsHideBySig属性的具体用法?C# MethodBase.IsHideBySig怎么用?C# MethodBase.IsHideBySig使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了MethodBase.IsHideBySig属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: M
//引入命名空间
using System;
using System.Reflection;
// The base class B contains an overloaded method M.
//
public class B
{
public virtual void M()
{
Console.WriteLine("B's M()");
}
public virtual void M(int x)
{
Console.WriteLine("B's M({0})", x);
}
}
// The derived class D hides one overload of the inherited
// method M.
//
public class D:
B
{
new public void M(int i)
{
Console.WriteLine("D's M({0})", i);
}
}
public class Test
{
public static void Main()
{
D dinst = new D();
// In C#, the method in the derived class hides by name and by
// signature, so the overload in the derived class hides only one
// of the overloads in the base class.
//
Console.WriteLine("------ List the overloads of M in the derived class D ------");
Type t = dinst.GetType();
foreach( MethodInfo minfo in t.GetMethods() )
{
if (minfo.Name=="M") {Console.WriteLine("Overload of M: {0} IsHideBySig = {1}, DeclaringType = {2}", minfo, minfo.IsHideBySig, minfo.DeclaringType);}
}
// The method M in the derived class hides one overload of the
// method in B. Contrast this with Visual Basic, which hides by
// name instead of by name and signature. In Visual Basic, the
// parameterless overload of M would be unavailable from D.
//
Console.WriteLine("------ Call the overloads of M available in D ------");
dinst.M();
dinst.M(42);
// If D is cast to the base type B, both overloads of the
// shadowed method can be called.
//
Console.WriteLine("------ Call the shadowed overloads of M ------");
B binst = dinst;
binst.M();
binst.M(42);
} //Main
} //Test
输出:
------ List the overloads of M in the derived class D ------ Overload of M: Void M(Int32) IsHideBySig = True, DeclaringType = B Overload of M: Void M() IsHideBySig = True, DeclaringType = B Overload of M: Void M(Int32) IsHideBySig = True, DeclaringType = D ------ Call the overloads of M available in D ------ B's M() D's M(42) ------ Call the shadowed overloads of M ------ B's M() B's M(42)