为什么不具有Text属性的所有System.Web.UI.WebControl类都实现ITextControl?

jru*_*ell 11 asp.net web-controls

我很好奇为什么只有一些System.Web.UI.WebControl控件在具有相同的接口属性时实现某些接口.

例如,有很多控件具有Text属性,但只有以下工具ITextControl:

  • 标签
  • 文字
  • DataBoundLiteral
  • 文本框
  • 列表控件

(TextBox和ListControl实际上实现了IEditableTextControl,它实现了ITextControl)

TableCell,Button,HyperLink等不是这样我必须编写这样的代码

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

if (textControl != null)
{
    textControl.Text = value;
}
else if (tableCell != null)
{
    tableCell.Text = value;
}
Run Code Online (Sandbox Code Playgroud)

而不是这个

control.Text = value;
Run Code Online (Sandbox Code Playgroud)

这是设计决定还是疏忽?

Bri*_*ins 1

我认为它的设计是好的,我不认为这是一个疏忽;在这些控件中,文本是控件用途的主要焦点。我确实明白你的观点,因为让控件利用更多此类接口会非常方便。