Reputation: 6312
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!
Upvotes: 2
Views: 19202
Reputation: 1
Upvotes: 0
Reputation: 99859
Choose the one for the technology you're using:
Windows Forms:
It's located in System.Windows.Forms.dll
in the System.Windows.Forms
namespace.
WPF: (probably not this one, because there's no relevant Controls
property in the WPF classes)
It's located PresentationFramework.dll
in the System.Windows.Controls
namespace.
Web Controls:
It's located System.Web.dll
in the System.Web.UI
namespace.
Upvotes: 9