Reputation: 81342
My base class does not contain a parameterless constructor.
So I can typically call the base class constructor like this:
public ItemFoldersForm(FormConstructor constuctorOptions): base(constuctorOptions.WindowTitle, constuctorOptions.TabName, constuctorOptions.TabButton)
{
}
All of that is pretty standard, but for ease of reuse I want to have a parameterless constructor in my derived class. This is because the constructor options are based on a random generator.
Something like this:
public ItemFoldersForm()
{
var constructorOptions = ConstructorOptions.GetRandomConstructorOptions();
base: // what to do here....
}
Is this concept possible with c#?
Upvotes: 0
Views: 75
Reputation: 636
You could define two constructors:
public ItemFoldersForm(FormConstructor constuctorOptions) : base(constuctorOptions.WindowTitle, constuctorOptions.TabName, constuctorOptions.TabButton)
{
}
public ItemFoldersForm() : this(ConstructorOptions.GetRandomConstructorOptions())
{
}
Use the default constructor to generate your random options, which are then passed to the overloaded constructor which passes on properties to the base.
Note that the only way to do this is before the body of the constructor.
Upvotes: 4