从.NET中的属性/方法返回类(不是对象)

时间:2016-02-17 20:38:49

标签: c# .net vb.net class return-type

我正在编写一个库,我希望Main类的属性返回,以便可以通过链接调用类方法。

Main main = new Main() main.Foo.Bar()

我还会在Main上有属性来返回对象实例。

Main main = new Main() main.Foo("name").Baz()

这将允许我将所有相关功能保留在单个类中,但只公开每个上下文中可用的方法。反正有吗?

1 个答案:

答案 0 :(得分:0)

这样的东西?

示例用法:

Dim main As New Main
main.Foo.Bar.SomeMethod()



Public Class Main

    Private m_Foo As Foo = New Foo()

    Public Property Foo As Foo
        Get
            Return m_Foo
        End Get
        Set(value As Foo)
            m_Foo = value
        End Set
    End Property
End Class


Public Class Foo

    Private m_Bar As Bar = New Bar

    Public ReadOnly Property Bar
        Get
            Return m_Bar
        End Get
    End Property

End Class


Public Class Bar

    Public Sub SomeMethod()

    End Sub

End Class