如何将委托指向扩展方法
How to point a delegate to an extension method
public class UITestCtrl
{
}
public static class Ext
{
public static void FindElement(this UITestCtrl clas)
{
}
}
public class Brwsr : UITestCtrl
{
public void FindElement()
{
}
}
现在,我正在尝试将委托指向扩展方法
private delegate void MyDell_();
MyDell_ dell = new MyDell_(Ext.FindElement());
我遇到错误:
Error CS7036 There is no argument given that corresponds to the
required formal parameter 'clas' of 'Ext.FindElement(UITestCtrl)'
谢谢
// 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
这是一个控制台应用程序,我使用了一个列表而不是 UITestCtrl:
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
}
}
public class UITestCtrl
{
}
public static class Ext
{
public static void FindElement(this UITestCtrl clas)
{
}
}
public class Brwsr : UITestCtrl
{
public void FindElement()
{
}
}
现在,我正在尝试将委托指向扩展方法
private delegate void MyDell_();
MyDell_ dell = new MyDell_(Ext.FindElement());
我遇到错误:
Error CS7036 There is no argument given that corresponds to the required formal parameter 'clas' of 'Ext.FindElement(UITestCtrl)'
谢谢
// 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
这是一个控制台应用程序,我使用了一个列表而不是 UITestCtrl:
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
}
}