BRO1408: Remove a redundant base type¶
enum E : int and class C : object name what the declaration means anyway: an enum's underlying type is int and a
class derives from object unless they say otherwise. Not a StyleCop rule (Roslynator RCS1042, Sonar S1939).
Example¶
Before¶
using System;
public enum Color : int
{
Red,
Green,
}
public class Shape : object, IDisposable
{
public void Dispose()
{
}
}
After¶
using System;
public enum Color
{
Red,
Green,
}
public class Shape : IDisposable
{
public void Dispose()
{
}
}
Why¶
A base type the compiler adds anyway suggests a choice that wasn't made: enum E : int reads like the size matters
(for interop or serialization) when it is just the default.
How the fix works¶
The base type is removed with its : when it is the only one, or with the , after it when interfaces follow.
Not reported¶
- Enums with another underlying type (
byte,long, ...). The check is semantic:int,Int32,System.Int32and an alias of it are all reported. - A base type named
Objectthat isn'tSystem.Object. - A comment or directive in the removed text.
Compared with StyleCop¶
StyleCop has no such rule. stylebro-migrate turns it off (see
Rules beyond StyleCop).