I have a constructor question for C#.
I have this class:
public partial class Signature : Form, ISignature
{
private readonly SignatureMediator mediator;
public Signature(SignatureMediator mediator)
{
this.mediator = mediator;
InitializeComponent();
}
.... more stuff
}
I want to construct this class like this:
public SignatureMediator(int someValue, int otherValue, int thirdValue)
: this(new Signature(this), someValue, otherValue, thirdValue)
// This is not allowed --^
{
// I don't see anyway to get this in to the ":this" part.
//Signature signature = new Signature(this);
}
public SignatureMediator(ISignature form, int someValue, int otherValue, int thirdValue)
{
SigForm = form;
SomeValue= someValue;
OtherValue= otherValue;
ThirdValue= thirdValue;
}
The : this( new SignatureThis(this) is not allowed (the this used in the constructor is not allowed).
Is there anyway to set this up without duplicating the assignment of the int values?
How about making the second constructor construct a
Signaturefromthisif theISignatureparameter isnull, otherwise using the providedISignature? You could then passnullfrom the first constructor to get the behavior you want.