| 屬性 | 值 |
|---|---|
| 規則識別碼 | CA2256 |
| 職稱 | 父介面中宣告的所有成員都必須在 DynamicInterfaceCastableImplementation-attributed 介面中實作 |
| 類別 | 使用方式 |
| 修正程式是中斷或非中斷 | 不中斷 |
| 在 .NET 10 中預設啟用 | 作為警告 |
原因
具有 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()
{
// ...
}
}
隱藏錯誤的時機
請勿隱藏此規則的警告。