tags:

views:

35

answers:

1

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 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
+1  A: 

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

You should avoid exposing nested types.

SLaks
As I see it, he already made Car a partial class..
codymanix
@codymanix: Yes; I edited.
SLaks
So how would you do this instead so that the final usage code doesn't change?
EdenMachine
@EdenMachine: You can't.
SLaks
@SLaks - thanks for your time on this. What would be the standard practice for doing what I'm trying to do?
EdenMachine
@EdenMachine: Standard practice would be to use a non-nested enum called `CarModels` or `CarTypes`.
SLaks