I am extending TextBox WebControl to work as a sort of “DateTextBox” which exposes it’s value as a property (DateValue) in the code-behind:
public sealed class DateTextBox : TextBox
{
public DateTime ?DateValue
{
/* ToDateFromUserInterface() and ToUserInterfaceString() are both
extension methods */
get
{
return
(
String.IsNullOrEmpty(Text) ?
new DateTime?() :
Text.ToDateFromUserInterface()
);
}
set
{
if (value != null) Text = ((DateTime)value).ToUserInterfaceString();
}
}
}
Given the fact that this control is only supposed to be used with dates, there’s no reason for it to inherrit the Text property from it’s parrent.
Is there any way to hide it?.. Other than implementing a NotImplementedException, like so:
new public String Text
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
You can use EditorBrowsable attribute. It will only hide the property from Intelisense, but won’t break compile time compatibility with base class.
Although you can still use the property if you know it’s name.
PS: Read user comments at the end of this article.
http://msdn.microsoft.com/en-us/library/system.componentmodel.editorbrowsableattribute.aspx