Inconsistent naming conventions can lead to confusion and errors when working in a team. This rule ensures that all generic type parameter names follow a consistent naming convention by checking them against a provided regular expression.
The default configuration follows Microsoft's recommended convention:
* Generic type parameter names must start with an upper case 'T', e.g. T
* The rest of the name should use Pascal casing, starting with an upper case character, e.g. TKey
* Short abbreviations of 2 letters can be capitalized, e.g. TFooID
* Longer abbreviations should be lowercased, e.g. TFooHtml
== How to fix it
To fix this issue, ensure that all generic type parameter names in your code follow the naming convention specified in the regular expression.
=== Code examples
==== Noncompliant code example
With the default parameter value `^T(([A-Z]{1,3}[a-z0-9]+)*([A-Z]{2})?)?$`:
[source,vbnet,diff-id=1,diff-type=noncompliant]
----
Public Class Foo(Of tkey) ' Noncompliant
End Class
----
==== Compliant solution
[source,vbnet,diff-id=1,diff-type=compliant]
----
Public Class Foo(Of TKey) ' Compliant
End Class
----
== Resources
=== Documentation
* Microsoft Learn - https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/generic-type-parameters[Generic Type Parameters (C# reference)]