Types should not extend certain base types
Types should not extend certain base types
Microsoft docsDescription
Exceptions should derive from System.Exception or one of its subclasses in the System namespace.
Do not create a subclass of System.Xml.XmlDocument if you want to create an XML view of an underlying object model or data source.
### Non-generic collections
Use and/or extend generic collections whenever possible. Do not extend non-generic collections in your code, unless you shipped it previously.
Examples of Incorrect Usage
Examples of Correct Usage
Cause
A type extends one of the following base types:
- System.ApplicationException
- System.Xml.XmlDocument
- System.Collections.CollectionBase
- System.Collections.DictionaryBase
- System.Collections.Queue
- System.Collections.ReadOnlyCollectionBase
- System.Collections.SortedList
- System.Collections.Stack
By default, this rule only looks at externally visible types, but this is configurable.
How to fix violations
To fix a violation of this rule, derive the type from a different base type or a generic collection.
Example
public class MyCollection : CollectionBase
{
}
public class MyReadOnlyCollection : ReadOnlyCollectionBase
{
}When to suppress
Do not suppress a warning from this rule for violations about System.ApplicationException. It is safe to suppress a warning from this rule for violations about System.Xml.XmlDocument. It is safe to suppress a warning about a non-generic collection if the code was released previously.