Reputation: 2466
public class UITestCtrl
{
}
public static class Ext
{
public static void FindElement(this UITestCtrl clas)
{
}
}
public class Brwsr : UITestCtrl
{
public void FindElement()
{
}
}
Now, I am trying to point delegate to extension method
private delegate void MyDell_();
MyDell_ dell = new MyDell_(Ext.FindElement());
I am getting error:
Error CS7036 There is no argument given that corresponds to the required formal parameter 'clas' of 'Ext.FindElement(UITestCtrl)'
Thanks
Upvotes: 3
Views: 4536
Reputation: 38367
// Your extension method is simply a static method taking one parameter and returning void,
// so an action is appropriate delegate signature:
Action<UITestCtrl> dell = Ext.FindElement;
UITestCtrl control = new UITestCtrl();
dell(control);// calling the extension method via the assigned delegate, passing the one parameter
Here's a console app where instead of UITestCtrl I have used a List:
static class Ext
{
public static void FindElement(List<string> test)
{
test.Add("blah");
}
}
class Program
{
static void Main(string[] args)
{
Action<List<string>> dell = Ext.FindElement;
var control = new List<string>();
dell(control);// calling the extension method via the assigned delegate
}
}
Upvotes: 4