diff --git a/docs/fundamentals/code-analysis/quality-rules/ca2257.md b/docs/fundamentals/code-analysis/quality-rules/ca2257.md index 4301494cd210a..2233f188e1bd5 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca2257.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca2257.md @@ -9,6 +9,8 @@ helpviewer_keywords: - DynamicInterfaceCastableImplementationAnalyzer - CA2257 author: Youssef1313 +dev_langs: +- CSharp --- # CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static' @@ -32,6 +34,10 @@ Since a type that implements `IDynamicInterfaceCastable` may not implement a dyn Mark the interface member `static`. +## Example + +:::code language="csharp" source="snippets/csharp/all-rules/ca2257.cs" id="snippet1"::: + ## When to suppress errors Do not suppress a warning from this rule. @@ -39,3 +45,4 @@ Do not suppress a warning from this rule. ## See also - [Usage warnings](usage-warnings.md) +- [CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md) diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2257.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2257.cs new file mode 100644 index 0000000000000..076dd90adad9f --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca2257.cs @@ -0,0 +1,19 @@ +using System.Runtime.InteropServices; + +namespace ca2257 +{ + // + [DynamicInterfaceCastableImplementation] + interface IExample + { + // This method violates the rule. + void BadMethod(); + + // This method satisfies the rule. + static void GoodMethod() + { + // ... + } + } + // +}