【问题标题】:Expose methods of nested class暴露嵌套类的方法
【发布时间】:2012-05-04 04:57:33
【问题描述】:

我有一个名为“ClientConnection”的公共类。在该类中,我有一个名为“FileTransfers(ByVal TransferID)”的公共只读属性。该属性返回“FileTransfer”类的对象。 FileTransfer 中的所有方法都设置为 public。

VS 能够发现父类“ClientConnection”中的方法。如何公开属性“FileTransfers(ByVal TransferID)”返回的子类“FileTransfer”中的方法?

Public Class ClientConnection
'irreverent code removed

   Public ReadOnly Property FileTransfers(ByVal TransferID As Integer)
    Get
        Dim obj As FileTransfer = OngoingFileTransfers(TransferID)
        If obj IsNot Nothing Then
            Return obj
        Else
            Return Nothing
        End If
    End Get
   End Property

End Class

Public Class FileTransfer()
  Public Sub StartTransfer() '<--- I need this discoverable in VS from ClientConnection's parent
   'do some stuff
  End Sub
End Class

我知道这可能很难理解。因此,如果您需要我澄清,请问。谢谢!

【问题讨论】:

    标签: .net vb.net oop


    【解决方案1】:

    我认为您只需要指明 FileTransfers 属性返回的类型即可。

    目前,属性声明末尾没有as 子句。

    Public ReadOnly Property FileTransfers(ByVal TransferID As Integer) as FileTransfer
     Get
         Dim obj As FileTransfer = OngoingFileTransfers(TransferID)
         If obj IsNot Nothing Then
             Return obj
         Else
             Return Nothing
         End If
     End Get
    End Property
    

    这听起来更像是一个方法操作而不是一个属性。

    【讨论】:

    • 哇,这么简单的修复。谢谢!我会在 5 分钟内接受这个作为答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 2023-03-09
    • 2017-05-24
    • 1970-01-01
    相关资源
    最近更新 更多