Avoid empty interfaces
An empty interface defines no members, hence no contract to implement. It is probably used as a marker to identify a group of types: for run-time identification use a custom attribute instead; for compile-time identification an empty interface is acceptable.
An empty interface implementing at least one other interface is not matched: implementing it requires implementing sub-interfaces members.
An empty interface implementing at least one other interface is not matched: implementing it requires implementing sub-interfaces members.
How to fix
Remove the interface or add members. If used as a marker, replace it with a custom attribute.
Estimated Debt: 10 minutes to discard the interface plus 3 minutes per implementing type.
Estimated Debt: 10 minutes to discard the interface plus 3 minutes per implementing type.
CQLinq source
This rule is written in CQLinq, C# LINQ over the NDepend code model. It ships with every new NDepend project: you can read it, adapt it, or use it as a starting point for your own custom rules.
// <Name>Avoid empty interfaces</Name>
// <Id>ND1212:AvoidEmptyInterfaces</Id>
warnif count > 0 from t in JustMyCode.Types where
t.IsInterface &&
t.NbMethods == 0 &&
!t.InterfacesImplemented.Any()
select new {
t,
t.TypesThatImplementMe,
Debt = (10 + 3*t.TypesThatImplementMe.Count()).ToMinutes().ToDebt(),
Severity = t.TypesThatImplementMe.Any() ? Severity.Medium : Severity.Low
}
//<Expl>The *{0}* is empty and is implemented by *{1}*. If the empty interface is being used to mark a set of classes, replace the interface with a custom attribute.</Expl>
//<Desc>
// An empty interface defines no members, hence no contract to implement. It
// is probably used as a marker to identify a group of types: for run-time
// identification use a custom attribute instead; for compile-time
// identification an empty interface is acceptable.
//
// An empty interface implementing at least one other interface is not
// matched: implementing it requires implementing sub-interfaces members.
//</Desc>
//<HowToFix>
// Remove the interface or add members. If used as a marker, replace it with
// a custom attribute.
//
// Estimated Debt: 10 minutes to discard the interface plus 3 minutes per
// implementing type.
//</HowToFix>
Open in the interactive Rules Explorer · All default rules
Object Oriented Design: all 14 items
- Avoid interfaces too big ND1200
- Base class should not use derivatives ND1201
- Class shouldn't be too deep in inheritance tree ND1202
- Class with no descendant should be sealed if possible ND1203
- Overrides of Method() should call base.Method() ND1204
- Do not hide base class methods ND1205
- A stateless class or structure might be turned into a static type ND1206
- Non-static classes should be instantiated or turned to static ND1207
- Methods should be declared static if possible ND1208
- Constructor should not call a virtual method ND1209
- Avoid the Singleton pattern ND1210
- Don't assign static fields from instance methods ND1211
- Avoid empty interfaces ND1212
- Avoid types initialization cycles ND1213