John,
1) Make sure every constructor in your base class takes a Control as a
parameter. The derived classes must call one of them.
public abstract BaseClass
{
public BaseClass(Control validationControl)
{
}
}
public class DerivedClass : BaseClass
{
public DerivedClass()
: base(GetControlSomehow())
{
}
public DerivedClass(Control validationControl)
: base(validationControl)
{
}
public Control GetControlSomehow()
{
// Do whatever it is you need to do to return a control.
}
}
2) Create a protected property or method that must be implemented in
the derived classes that returns a reference to a Control.
public abstract BaseClass
{
protected abstract ValidationControl { get; }
public void DoSomething()
{
// This line gets a reference from the derived class.
Control control = ValidationControl;
}
}
public class DerivedClass : BaseClass
{
protected override ValidationControl
{
get
{
// Return a reference to a Control.
}
}
}
These are the most common ways I do it.
Brian
John B wrote:
I have a variable in a base class defined as:
protected Control validationControl;
How can I ensure that it is set is any dervied classes. I see that
you cannot set variables to abstract.
Thanks