我的代码的相关部分如下。在MyTreeView
类中(下面的最后一个代码块),代码行TncExtensions.TncNodeAdd(this, myTreeViewNode);
生成错误CS7036 There is no argument given that corresponds to the required formal parameter 'myTreeViewNode' of 'TncExtensions.TncNodeAdd(TreeNodeCollection, MyTreeView_Abstract, MyTreeViewNode_Abstract)'
为什么编译器无法确定我的 TreeNodeCollection 扩展方法的第二个形参是什么?
public static class TncExtensions
{
public static int TncNodeAdd(this TreeNodeCollection nodes, MyTreeView_Abstract myTreeView, MyTreeViewNode_Abstract myTreeViewNode)
{
return myTreeView.Nodes.Add(myTreeViewNode);
}
}
public abstract class MyTreeViewNode_Abstract : TreeNode
{
public MyTreeViewNode_Abstract(string text) : base(text)
{
}
}
public class MyTreeViewNode : MyTreeViewNode_Abstract
{
public MyTreeViewNode(string text) : base(text)
{
}
}
public abstract class MyTreeView_Abstract : TreeView
{
}
public class MyTreeView : MyTreeView_Abstract
{
public void CreateTree()
{
MyTreeViewNode myTreeViewNode = new MyTreeViewNode("node text");
TncExtensions.TncNodeAdd(this, myTreeViewNode);
}
}