As stated in the question, is there any difference in the meaning of the two as applied to the Controls of .NET. Or are they alias of one another?
.NET Custom Control vs User Control – Key Differences
custom-controlnetwinforms
Related Solutions
I've used BDD extensively at many big clients, and seen it used in even more. If your organisation is hesitant about adopting the automation side, you can still focus on having the conversations between testers, developers and business people - this has really helped in a number of places.
At one .NET client we started automating Fitnesse.NET backed by FitSharp, but moved away from it when we realised that everyone who was interested in reading the automated scenarios was technical enough to read code. We were using WPF, so I wrote an automation tool to help us, and mirrored some of the things we were doing in a toy application. You can see the scenarios I wrote here. The way in which I've done this is really similar to what we were doing on the client site. I've also heard good things about SpecFlow, so either way forward should work.
As well as catching the occasional bug, talking through the scenarios really helped us understand what it was we were trying to achieve before we started coding, and we found many edge-cases as a result of the discussions. Every single project I've seen take up BDD has found benefit in it, with the one exception of a project which was only started because the sponsor wanted to use up his budget so he could be sure of getting it again the next year (the transparency around business value in BDD really annoys people who are gaming the system with things like this).
I have also put together a page on BDD which could help anyone who's new to it.
Lastly, you might want to check out Dan North's talk on selling BDD to the business.
As I can't use true multiple inheritance in C#, how would I design this to be able to share the methods and properties?
This is the right way to share the methods and properties. But:
The trouble now is that in my extendedTextBox class I can't cast my extendedTextBox as a 'BaseExtendedControl' to use the extension methods, as the extendedTextBox inherits from the standard TextBox class like this:
public class ExtendedTextBox : TextBox, IExtendedControl
so there's no common base to cast ExtendedTextBox as 'BaseExtendedControl' as it doesn't inherit from it.
Yes, you're right there is no common class, but you can solve the problem by casting to the IExtentedControl
interface which is common to your classes and contains the methods that you need. So what about:
public static class ExtendedControlHelper
{
public static void AddRequiredFieldValidator(this IExtendedControl control)
{
control.rfv = new RequiredFieldValidator();
control.rfv.ErrorMessage = control.RequiredMessage;
ConfigureAndAddValidator(control, control.rfv);
}
public static void ConfigureAndAddValidator(this IExtendedControl control, BaseValidator validator)
{
validator.ControlToValidate = control.ID;
validator.Display = ValidatorDisplay.Dynamic;
validator.CssClass = "validationMessage ";
validator.CssClass += control.ValidatorCssClass;
validator.EnableClientScript = control.ClientScript;
control.Controls.Add(validator);
}
}
I don't think you need to implement the IExtendedControl
interface in the ExtendedControlHelper
class. Moreover I corrected the grammar of the interface name from IExtendendControl
to IExtendedControl
.
EDIT :
Another solution could be to use the dynamic
keyword. The dynamic keyword is like object
but the type is checked at run time instead of compile time:
public static class ExtendedControlHelper
{
public static void AddRequiredFieldValidator(this dynamic control)
{
//...
}
public static void ConfigureAndAddValidator(this dynamic control, BaseValidator validator)
{
//...
}
}
The dynamic type doesn't exist at run time because it's solved by the compiler, so if you write this: myExtendedTextBox.AddRequiredFieldValidator();
the method is solved as
//...
public static void AddRequiredFieldValidator(this ExtendedTextBox control)
{
//...
}
and so on. So the type can change continuously at run time.
For more informations give a look here.
Best Answer
A user control is a composition of existing controls while a custom control is a control derived from one base control. This might be better in stackoverflow btw.