Trying to set up an extension method in .Net 3.0 using generics and I get an error message, details above on the line:
foreach(Control childControl in parent.Controls)
Am I missing a using directive or assembly reference?
Thanks
What I am trying to do is set this up (below) as an extender function:
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;
}
}
}
I am missing a reference to the system.core.dll… its driving me nuts!
Choose the one for the technology you’re using:
Windows Forms:
It’s located in
System.Windows.Forms.dllin theSystem.Windows.Formsnamespace.WPF: (probably not this one, because there’s no relevant
Controlsproperty in the WPF classes)It’s located
PresentationFramework.dllin theSystem.Windows.Controlsnamespace.Web Controls:
It’s located
System.Web.dllin theSystem.Web.UInamespace.