将 c# 转换为具有不同参数 vb.net 基类重写函数



我需要您的帮助才能将重写的函数从 c# 转换为 vb.net。 故事是这样的:

c# 代码有一个名为 TreeViewerDataProviderBase 的基类,其函数存根如下所示:

Protected Overridable Function CreateTreeNode(parentNode As TreeNodePath, text As String, path As String, isFile As Boolean, addDummyNode As Boolean, isSpecialFolder As Boolean) As TreeNodePath

另一个类子类 TreeViewerDataProviderBase,并使用以下存根覆盖基函数:

    protected virtual TreeNodePath CreateTreeNode(System.Windows.Forms.TreeNodeCollection parentCollection, TreeNodePath parentNode, Datomp.Win32.ShellItem shellItem)

如您所见,基函数和被覆盖函数具有相同的前 2 个参数,但其余参数不同。

当我尝试将其转换为 vb.net 时,我得到:

        Protected Overridable Function CreateTreeNode(parentCollection As System.Windows.Forms.TreeNodeCollection, parentNode As TreeNodePath, shellItem As DotNetParts.Win32.ShellItem) As TreeNodePath

这给了我一个错误,即 CreateTreeNode 覆盖了基类中的方法,并且必须声明为"覆盖"。

但是,当我将其从可覆盖更改为可覆盖时,我收到另一个错误,即它不会覆盖基类中的方法! 这是一个先有鸡还是先有蛋的问题。

我是一个 c# 人,所以我不明白为什么这不行。 如果我尝试删除覆盖,我会收到另一个错误,它覆盖了基类函数! 咳咳。

一些 VB.NET/C#天才可以帮助我转换它吗?

我按照山姆·斧头(Sam Axe(上面所说的方式解决了问题,并将Overridable替换为Overloads

所以这个:

Protected Overridable Function CreateTreeNode(parentCollection As System.Windows.Forms.TreeNodeCollection, parentNode As TreeNodePath, shellItem As DotNetParts.Win32.ShellItem) As TreeNodePath

变成了这个:

Protected Overloads Function CreateTreeNode(parentCollection As System.Windows.Forms.TreeNodeCollection, parentNode As TreeNodePath, shellItem As DotNetParts.Win32.ShellItem) As TreeNodePath

最新更新