Skip to content

Commit a551402

Browse files
authored
Add code example for CA2257 rule (#49109) (#49110)
1 parent 8aef630 commit a551402

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/fundamentals/code-analysis/quality-rules/ca2257.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ helpviewer_keywords:
99
- DynamicInterfaceCastableImplementationAnalyzer
1010
- CA2257
1111
author: Youssef1313
12+
dev_langs:
13+
- CSharp
1214
---
1315
# CA2257: Members defined on an interface with the 'DynamicInterfaceCastableImplementationAttribute' should be 'static'
1416

@@ -32,10 +34,15 @@ Since a type that implements `IDynamicInterfaceCastable` may not implement a dyn
3234

3335
Mark the interface member `static`.
3436

37+
## Example
38+
39+
:::code language="csharp" source="snippets/csharp/all-rules/ca2257.cs" id="snippet1":::
40+
3541
## When to suppress errors
3642

3743
Do not suppress a warning from this rule.
3844

3945
## See also
4046

4147
- [Usage warnings](usage-warnings.md)
48+
- [CA2256: All members declared in parent interfaces must have an implementation in a DynamicInterfaceCastableImplementation-attributed interface](ca2256.md)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace ca2257
4+
{
5+
//<snippet1>
6+
[DynamicInterfaceCastableImplementation]
7+
interface IExample
8+
{
9+
// This method violates the rule.
10+
void BadMethod();
11+
12+
// This method satisfies the rule.
13+
static void GoodMethod()
14+
{
15+
// ...
16+
}
17+
}
18+
//</snippet1>
19+
}

0 commit comments

Comments
 (0)