tags:

views:

1028

answers:

1

Hi,

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!

+6  A: 

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.

280Z28
Yeah I mean just make sure you have the reference to the DLL and you've got the using directive or access it via its fully-qualified name.
James D
Thanks for the help, I edited the question as this better explains what I am trying to do, extendor function for web control .FindControl, still getting errors and tired.
flavour404