| 属性 | 值 |
|---|---|
| 规则 ID | CA2256 |
| 标题 | 在父接口中声明的所有成员必须在 DynamicInterfaceCastableImplementation-attributed 接口中具有实现 |
| 类别 | 使用情况 |
| 修复是中断修复还是非中断修复 | 非中断 |
| 在 .NET 9 中默认启用 | 作为警告 |
原因
使用 DynamicInterfaceCastableImplementationAttribute 的接口有一个未实现的成员。
规则说明
具有特性 DynamicInterfaceCastableImplementationAttribute 的类型为一个用于实现 IDynamicInterfaceCastable 类型的类型充当接口实现。 因此,它必须提供继承接口中定义的所有成员的实现,因为若非如此,实现 IDynamicInterfaceCastable 的类型将不会提供它们。
如何解决冲突
实现缺失的接口成员。
Example
interface IParent
{
void ParentMethod();
}
// This interface violates the rule.
[DynamicInterfaceCastableImplementation]
interface IBadChild : IParent
{
static void ChildMethod()
{
// ...
}
}
// This interface satisfies the rule.
[DynamicInterfaceCastableImplementation]
interface IGoodChild : IParent
{
static void ChildMethod()
{
// ...
}
void IParent.ParentMethod()
{
// ...
}
}
何时禁止显示错误
不禁止显示此规则发出的警告。