diff --git a/rules/S4052/csharp/metadata.json b/rules/S4052/csharp/metadata.json index 1cffd7a6d6c..c26a2044d58 100644 --- a/rules/S4052/csharp/metadata.json +++ b/rules/S4052/csharp/metadata.json @@ -28,7 +28,7 @@ "sqKey": "S4052", "scope": "All", "defaultQualityProfiles": [ - + "Sonar way" ], "quickfix": "unknown" } diff --git a/rules/S4052/csharp/rule.adoc b/rules/S4052/csharp/rule.adoc index d71ea722762..0bfeac6528f 100644 --- a/rules/S4052/csharp/rule.adoc +++ b/rules/S4052/csharp/rule.adoc @@ -1,24 +1,26 @@ == Why is this an issue? -With the advent of .NET framework version 2, certain practices have become obsolete. - -In particular, exceptions should now extend ``++System.Exception++`` instead of ``++System.ApplicationException++``. Similarly, generic collections should be used instead of the older, non-generic, ones. Finally when creating an XML view, you should not extend ``++System.Xml.XmlDocument++``. +With the advent of .NET Framework 2.0, certain practices and types have become obsolete. +In particular, exceptions should now extend `System.Exception` instead of `System.ApplicationException`. Similarly, generic collections should be used instead of the older, non-generic, ones. Finally when creating an XML view, you should not extend `System.Xml.XmlDocument`. This rule raises an issue when an externally visible type extends one of these types: -* ``++System.ApplicationException++`` -* ``++System.Xml.XmlDocument++`` -* ``++System.Collections.CollectionBase++`` -* ``++System.Collections.DictionaryBase++`` -* ``++System.Collections.Queue++`` -* ``++System.Collections.ReadOnlyCollectionBase++`` -* ``++System.Collections.SortedList++`` -* ``++System.Collections.Stack++`` +* https://learn.microsoft.com/en-us/dotnet/api/system.applicationexception[System.ApplicationException] +* https://learn.microsoft.com/en-us/dotnet/api/system.xml.xmldocument[System.Xml.XmlDocument] +* https://learn.microsoft.com/en-us/dotnet/api/system.collections.collectionbase[System.Collections.CollectionBase] +* https://learn.microsoft.com/en-us/dotnet/api/system.collections.dictionarybase[System.Collections.DictionaryBase] +* https://learn.microsoft.com/en-us/dotnet/api/system.collections.queue[System.Collections.Queue] +* https://learn.microsoft.com/en-us/dotnet/api/system.collections.readonlycollectionbase[System.Collections.ReadOnlyCollectionBase] +* https://learn.microsoft.com/en-us/dotnet/api/system.collections.sortedlist[System.Collections.SortedList] +* https://learn.microsoft.com/en-us/dotnet/api/system.collections.stack[System.Collections.Stack] + +== How to fix it +=== Code examples -=== Noncompliant code example +==== Noncompliant code example -[source,csharp] +[source,csharp,diff-id=1,diff-type=noncompliant] ---- using System; using System.Collections; @@ -31,13 +33,12 @@ namespace MyLibrary } ---- +==== Compliant solution -=== Compliant solution - -[source,csharp] +[source,csharp,diff-id=1,diff-type=compliant] ---- using System; -using System.Collections; +using System.Collections.ObjectModel; namespace MyLibrary { @@ -47,7 +48,6 @@ namespace MyLibrary } ---- - ifdef::env-github,rspecator-view[] ''' @@ -58,5 +58,4 @@ ifdef::env-github,rspecator-view[] Refactor this type not to derive from an outdated type '{0}'. - endif::env-github,rspecator-view[]