Search code examples
c#syntaxconstructorderived-class

Shorthand for derived constructor just passing to base


* NOT THIS QUESTION: Calling the base constructor in C# *


I know how to call this or base to chain constructors.

Even so, occasionally I end up with a base constructor with many parameters, and a derived class which doesn't change the constructor at all. (All the derived class is doing is changing some of the implementation details of virtual methods.) When that happens I still have to define the derived constructor and pass all the params through to the base constructor.

Question: Is there any syntax sugar that says "this class doesn't declare it's own constructor, it uses an exact replica of the base constructor."


No doubt the number of params is a CodeSmell, and I should try to fix that or create a ParamObject to hold them all,but that's not the topic of the question.

There are many other ways that I could solve this problem, I'm interested in specifically whether a syntax exists to let me solve it that way.


Solution

  • No - constructors are not inherited, and there's no syntax to "automagically" call base constructors that have the same parameters.