Why don't all System.Web.UI.WebControl classes with Text properties implement ITextControl?

时光总嘲笑我的痴心妄想 提交于 2019-12-21 03:50:06

问题


I'm curious why only some System.Web.UI.WebControl controls implement certain interfaces when they have the same properties of an interface.

For instance, there are plenty of controls that have a Text property but only the following implement ITextControl:

  • Label
  • Literal
  • DataBoundLiteral
  • TextBox
  • ListControl

(TextBox and ListControl actually implement IEditableTextControl which implements ITextControl)

TableCell, Button, HyperLink and others don't so I have to write code like this

ITextControl textControl = control as ITextControl;
TableCell tableCell = control as TableCell;

if (textControl != null)
{
    textControl.Text = value;
}
else if (tableCell != null)
{
    tableCell.Text = value;
}

instead of this

control.Text = value;

Was this a design decision or an oversight?


回答1:


I think it was designed ok, I don't think it was an oversight; those are the controls where text is the primary focus of the purpose of the control. I do see your point because that would be very convenient to have controls utilize more of these types of interfaces.



来源:https://stackoverflow.com/questions/2609066/why-dont-all-system-web-ui-webcontrol-classes-with-text-properties-implement-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!