Search code examples
f#xmlunit-2

Inheriting a C# class that has only a private constructor


I'd like to subclass the XMLUnit.NET CompareConstraint class in my F# code.

However, that class only has a single private constructor. If I try to inherit it, I get this compile error:

This 'inherit' declaration specifies the inherited type but no arguments. Consider supplying arguments, e.g. 'inherit BaseType(args)'.

Is there any way to inherit a class without a public constructor in F#?


Solution

  • This is not an F# limitation – it is not possible to inherit from a type with only private constructors in any .NET language.