62 lines
2.0 KiB
Plaintext
62 lines
2.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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:
|
|
|
|
* 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
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
using System;
|
|
using System.Collections;
|
|
|
|
namespace MyLibrary
|
|
{
|
|
public class MyCollection : CollectionBase // Noncompliant
|
|
{
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
using System;
|
|
using System.Collections.ObjectModel;
|
|
|
|
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[]
|