-1

我正在使用 BrightIdeas 软件中的 TreeListView 控件。看起来不错,但我对代表不熟悉,示例是用 c# 编写的。有人可以帮我把它翻译成 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

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

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

1 回答 1

1

您的 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
于 2017-02-23T14:46:45.447 回答