更新:2007 年 11 月
| TypeName | DoNotHideBaseClassMethods | 
| CheckId | CA1061 | 
| 类别 | Microsoft.Design | 
| 是否重大更改 | 是 | 
原因
派生类型声明一个与它的某个基方法具有相同名称和相同参数数目的方法;一个或多个参数是基方法中对应参数的基类型;任何其余参数的类型都与基方法中的对应参数完全相同。
规则说明
如果派生方法的参数签名只是在类型方面有所不同,而且与基方法的参数签名中的对应类型相比,这些类型的派生方式更弱,则基类型中的方法将被派生类型中的同名方法隐藏。
如何修复冲突
若要修复与该规则的冲突,请移除或重命名该方法,或者更改参数签名,使该方法不隐藏基方法。
何时禁止显示警告
不要禁止显示此规则发出的警告。
示例
下面的示例演示一个与该规则冲突的方法。
using System;
namespace DesignLibrary
{
   class BaseType
   {
      internal void MethodOne(string inputOne, object inputTwo)
      {
         Console.WriteLine("Base: {0}, {1}", inputOne, inputTwo);
      }
      internal void MethodTwo(string inputOne, string inputTwo)
      {
         Console.WriteLine("Base: {0}, {1}", inputOne, inputTwo);
      }
   }
   class DerivedType : BaseType
   {
      internal void MethodOne(string inputOne, string inputTwo)
      {
         Console.WriteLine("Derived: {0}, {1}", inputOne, inputTwo);
      }
      // This method violates the rule.
      internal void MethodTwo(string inputOne, object inputTwo)
      {
         Console.WriteLine("Derived: {0}, {1}", inputOne, inputTwo);
      }
   }
   class Test
   {
      static void Main()
      {
         DerivedType derived = new DerivedType();
         // Calls DerivedType.MethodOne.
         derived.MethodOne("string1", "string2");
         // Calls BaseType.MethodOne.
         derived.MethodOne("string1", (object)"string2");
         // Both of these call DerivedType.MethodTwo.
         derived.MethodTwo("string1", "string2");
         derived.MethodTwo("string1", (object)"string2");
      }
   }
}