Total .NET Analyzer Rule Documentation  

AbstractConstructor Rule

Do not declare public constructors in abstract types.

Remarks

Declaring public constructors in abstract types does not make sense, since abstract types cannot be instantiated.

For example, the following sample includes code that can only be called from a derived class, so marking the constructor as public is misleading:


' VB
Public MustInherit Class Test
Public Sub New()
' Code here...
End Sub
End Class

// C#
abstract class Test
{
public Test()
{
// Code here...
}
}

Resolution

Change the above to:

' VB (remove the MustInherit keyword)
Public Class Test
Protected Sub New()

End Sub
End Class

// C# (remove the abstract keyword)
class Test
{
protected Test()
{

}
}

See Also

Using Constructors and Destructors

Type Members

Abstract Classes