| 屬性 | 值 |
|---|---|
| 規則識別碼 | CA2257 |
| 職稱 | 在具有 'DynamicInterfaceCastableImplementationAttribute' 的介面上定義的成員應該是 'static' |
| 類別 | 使用方式 |
| 修正程式是中斷或非中斷 | 不中斷 |
| 在 .NET 10 中預設啟用 | 作為警告 |
原因
介面成員未明確實作或標示 static為 。
檔案描述
由於實作的 IDynamicInterfaceCastable 型別可能不會在元資料中實作動態介面,呼叫非明確定義於此型別的實例介面成員,在執行時很可能會失敗。 為避免執行時錯誤,請標記新的介面成員 static。
如何修正違規
標記介面成員 static。
Example
[DynamicInterfaceCastableImplementation]
interface IExample
{
// This method violates the rule.
void BadMethod();
// This method satisfies the rule.
static void GoodMethod()
{
// ...
}
}
隱藏錯誤的時機
請勿隱藏此規則的警告。