From c49d97a31877af92ce10927fb2acc656be470365 Mon Sep 17 00:00:00 2001 From: kurnakovv Date: Mon, 6 Oct 2025 15:23:16 +0900 Subject: [PATCH] Add example for CA1005 rule (#48911) --- .../code-analysis/quality-rules/ca1005.md | 6 +++++ .../snippets/csharp/all-rules/ca1005.cs | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1005.cs diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1005.md b/docs/fundamentals/code-analysis/quality-rules/ca1005.md index 0917340f090a3..9a5a466bf55bb 100644 --- a/docs/fundamentals/code-analysis/quality-rules/ca1005.md +++ b/docs/fundamentals/code-analysis/quality-rules/ca1005.md @@ -10,6 +10,8 @@ helpviewer_keywords: - CA1005 author: gewarren ms.author: gewarren +dev_langs: +- CSharp --- # CA1005: Avoid excessive parameters on generic types @@ -35,6 +37,10 @@ The more type parameters a generic type contains, the more difficult it is to kn To fix a violation of this rule, change the design to use no more than two type parameters. +## Example + +:::code language="csharp" source="snippets/csharp/all-rules/ca1005.cs" id="snippet1"::: + ## When to suppress warnings Do not suppress a warning from this rule unless the design absolutely requires more than two type parameters. Providing generics in a syntax that is easy to understand and use reduces the time that is required to learn and increases the adoption rate of new libraries. diff --git a/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1005.cs b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1005.cs new file mode 100644 index 0000000000000..26349992056fd --- /dev/null +++ b/docs/fundamentals/code-analysis/quality-rules/snippets/csharp/all-rules/ca1005.cs @@ -0,0 +1,22 @@ +namespace ca1005 +{ + // + // This class violates the rule. + public class TooManyTypeParameters + { + public void M1(T t, K k, V v) + { + // ... + } + } + + // This class satisfies the rule. + public class CorrectTypeParameters + { + public void M1(T t, K k) + { + // ... + } + } + // +}