开发者

Exposing a class through another class with consistent naming in .net

In the pseudo code below, if I have two classes and I want one class to be initialized in the other class without the name having to be different, how would I accomplish this?

'==Car.vb==
Public Class Car
    Public Model as New Car.Model()
End Class

'==Model.vb==
Partial Class Car
    Public Class Model
        Public Enum Types
            BMW
            Audi
            Yugo
        End Enum
        'Do Something
    End Class
End Class

'==ASPX page==
Dim c as New Car()
c.Model = Car.Model.Types.BMW

Obviously this doesn't work because the New Model object is named the same thing as the Car.Model class. I just don't want to have to create a "Model" object also every time I define a car class but I also don't want the names to be all stupid like this:

'==Car.vb==
Public Class Car
    Public Model as New Car.CarModel()
End Class

'==Model.vb==
Partial Class Car
    Public Class CarModel
        Public Enum Types
            BMW
            Audi
            Yugo
        End Enum
        'Do Something
    End Class
End Class

'==ASPX page==
Dim开发者_如何学Go c as New Car()
c.Model = Car.CarModel.Types.BMW

Is there a better way of doing this so I get the result I want for my usage code?

'==ASPX page==
Dim c as New Car()
c.Model = Car.Model.Types.BMW


This is not possible, and is in general a bad idea.

You should avoid exposing nested types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜