I have the following class
public class UIControl
{
public string FName{ get; set; }
public HtmlInputCheckBox SelectCheckBox { get; set; }
public bool OverrideSelect { get; set; }
//Want to throw an ApplicationExceptioh if developer uses this constructor and passes
//chkSelect = null
public UIControl(string sFieldName, HtmlInputCheckBox chkSelect)
{
this.FName= sFieldName;
this.SelectCheckBox = chkSelect;
}
public UIControl(string sFieldName, HtmlInputCheckBox chkSelect, bool overrideSelect)
: this(sFieldName, chkSelect)
{
OverrideSelect = overrideSelect;
}
}
I want to make sure that the developer uses the first constructor only when chkSelect is not null.
I want to do a:
throw new ApplicationException("Dev is using the incorrect constructor");
You can use a private constructor thus:
There are lots of variants, but as a general rule, have less specific constructors calling more specific ones. For example, the following would also work in your case: