试图在.Net 3.0中使用泛型设置扩展方法,并且收到错误消息,上面的详细信息该行:无法找到名称空间名称'Control'的类型(是否缺少使用指令或程序集引用?)
foreach(Control childControl in parent.Controls)
我是否缺少使用指令或程序集引用?
感谢
我所试图做的是设置此(下同)作为扩展功能:
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;
}
}
}
我缺少一个参考system.core.dll ...它使我抓狂!
是的,我的意思是确保你有DLL的引用,你有使用指令或通过它的完全合格的名称访问它。 – 2009-07-23 00:50:42