将委托从 c# 翻译成 VB.NET

Translate Delegates from c# to VB.NET

我正在使用 BrightIdeas 软件的 TreeListView 控件。看起来不错,但我不熟悉委托,这个例子是用 c# 编写的。有人可以帮我一下吗 t运行 将此设置为 VB.NET?

这是例子:

    this.treeListView.CanExpandGetter = delegate(object x) {
        Return ((MyFileSystemInfo) x).IsDirectory;
    };

这是我对意图的最佳猜测(显然是错误的)

    Dim expander As TreeListView.CanExpandGetterDelegate
    expander = AddressOf IsReportPopulated
    '// CanExpandGetter Is called very often! It must be very fast.
    Me.treeListView.CanExpandGetter = expander(x As Object) ' no idea where we are getting the object from

函数定义为

Private Function IsReportPopulated(x As Object) As Boolean
    Dim myreport As ADCLReport = CType(x, ADCLReport)
    If myreport.Chambers.Count > 0 Or myreport.Electrometers.Count > 0 Then Return True
    Return False
End Function

根据建议,运行 通过 t运行slator。看起来不太对劲。输出:

thisPublic Delegate Sub ((ByVal Unknown As x)
{Return(CType(x,MyFileSystemInfo)).IsDirectory
UnknownUnknown

您的 C# 代码是在 C# 具有 lambda 之前您必须尝试编写 lambda 的方式 - 通常写为:

this.treeListView.CanExpandGetter = (object x) =>
{
    return ((MyFileSystemInfo)x).IsDirectory;
};

VB 等价于:

Me.treeListView.CanExpandGetter = Function(x As Object)
    Return DirectCast(x, MyFileSystemInfo).IsDirectory
End Function