I've looked and didn't quite find similar to what I'm dealing with. Hopefully a solution, or offer for better implementation. I have a class that may be passed with an optional parameter that is preserved to the instance created. I then have a derived class with similar optional parameter, but in its non-parameter constructor does other preparation stuff regardless of the optional parameter. What would be the correct way to have it call the base-class parameter constructor, yet still do the non-parameter constructor of the derived.
public class MyBaseClass
{
protected object preserveParm;
protected int someValue;
public MyBaseClass()
{
someValue = 1;
}
public MyBaseClass( object SomeParm ) : this()
{
preserveParm = SomeParm;
}
}
public class DerivedClass : MyBaseClass
{
private int customSecondaryProp;
private DateTime when;
public DerivedClass()
{
customSecondaryProp = 10;
someValue = 5;
}
public DerivedClass( object SomeParm ) : base( SomeParm )
{
when = DateTime.Now;
}
}
So, if I do a
DerivedClass test = new DerivedClass( "testing" );
I need it to hit the base class to preserve the parameter, yet ALSO hit the derived class's non-parameter to set the sample bogus values.
As it stands now, the Derived parameter method is hit, which then hits the base class's parameter constructor which calls the "this()" of the base class, and returns up the chain to the DerivedClass parameter constructor, finishes itself, but never hits the DerivedClass constructor. Is there a way to force both the baseclass parameterless AND the DerivedClass parameterless constructor?