From c85c071fcbd9d3397b986ac1a73234ec22d96cc2 Mon Sep 17 00:00:00 2001 From: kurnakovv Date: Mon, 13 Oct 2025 16:15:55 +0900 Subject: [PATCH] Add code example for CA2256 rule (#49105) --- .../code-analysis/quality-rules/ca2256.md | 7 ++++ .../snippets/csharp/all-rules/ca2256.cs | 36 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2256.cs diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2256.md b/docs/fundamentals/code-analysis/quality-rules/ca2256.md index 141b1597ee659..d6b2ec326839a 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2256.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2256.md @@ -9,6 +9,8 @@ helpviewer_keywords: - DynamicInterfaceCastableImplementationAnalyzer - CA2256 author: Youssef1313 +dev_langs: +- CSharp --- # CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface @@ -32,6 +34,10 @@ Types attributed with + 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() + { + // ... + } + } + // +}