rspec/rules/S4052/csharp/rule.adoc

63 lines
1.4 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
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++``.
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++``
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
using System.Collections;
namespace MyLibrary
{
public class MyCollection : CollectionBase // Noncompliant
{
}
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
using System;
using System.Collections;
namespace MyLibrary
{
public class MyCollection : Collection<T>
{
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Refactor this type not to derive from an outdated type '{0}'.
endif::env-github,rspecator-view[]