Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/fundamentals/code-analysis/quality-rules/ca1005.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ helpviewer_keywords:
- CA1005
author: gewarren
ms.author: gewarren
dev_langs:
- CSharp
---
# CA1005: Avoid excessive parameters on generic types

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace ca1005
{
//<snippet1>
// This class violates the rule.
public class TooManyTypeParameters<T, K, V>
{
public void M1(T t, K k, V v)
{
// ...
}
}

// This class satisfies the rule.
public class CorrectTypeParameters<T, K>
{
public void M1(T t, K k)
{
// ...
}
}
//</snippet1>
}
Loading