代码检查:参数可以声明为基类型
该检查会报告方法参数声明为具体类型,即使该方法仅通过基类型或接口来使用它。 使用更不具体的类型可以使 API 更灵活,同时不会改变方法的行为。
示例
interface IFoo
{
void Run();
}
class Foo : IFoo
{
public void Run() { }
}
class C
{
private static void Execute(Foo foo)
{
foo.Run();
}
}
interface IFoo
{
void Run();
}
class Foo : IFoo
{
public void Run() { }
}
class C
{
private static void Execute(IFoo foo)
{
foo.Run();
}
}
快速修复
将参数类型更改为建议的基类型或接口。
2026年 5月 8日