3

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#?

Eero Helenius
  • 2,584
  • 21
  • 22
  • I would add that preventing inheritance is the whole point of having a private constructor. Whoever made that class specificlly didn't want you to inherit from it. – Fyodor Soikin Oct 07 '16 at 14:37
  • Yeah, that makes sense. @ildjarn: if you want to put your comment into an answer, I'll accept it. – Eero Helenius Oct 07 '16 at 14:44

1 Answers1

6

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

ildjarn
  • 62,044
  • 9
  • 127
  • 211