尝试使用泛型在.Net 3.0中设置扩展方法,我收到一条错误消息,上面的详细信息如下:
foreach(Control childControl in parent.Controls)
Run Code Online (Sandbox Code Playgroud)
我错过了使用指令或汇编引用吗?
谢谢
我想要做的是将其设置为(下面)作为扩展函数:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
namespace System.Runtime.CompilerServices
{
public static class ControlHelper
{
public static T FindControl<T>(this Control parent, string controlName) where T : Control
{
T found = parent.FindControl(controlName) as T;
if (found != null)
return found;
foreach (Control childControl in parent.Controls)
{
found = childControl.FindControl(controlName) as T;
if (found != null)
break;
}
return found;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了对system.core.dll的引用...它让我疯了!
选择您正在使用的技术:
Windows窗体:
它位于System.Windows.Forms.dll在System.Windows.Forms命名空间.
WPF :(可能不是这个,因为ControlsWPF类中没有相关属性)
它位于PresentationFramework.dll在System.Windows.Controls命名空间.
网络控制:
它位于System.Web.dll在System.Web.UI命名空间.
| 归档时间: |
|
| 查看次数: |
17840 次 |
| 最近记录: |