[BUG] Naming with brackets in VB.Net (v4.0.30)
Posted: Wed  31 Aug 2011 13:55
				
				I found another bug in the code generation for VB.Net, this time in the ObjectContext template.
Backstory: Our method provider calls a collection of his 'Modulvariablen' a 'Modul'. The german plural of 'Modul' is 'Module'. Because we want to keep as close as possible to his naming schema this means a bit of trouble in Visual Basic, because 'Module' is also a language keyword. But you can work around that with using '[Module]' instead.
The ObjectContext template actually does this fine for the property declaration, but it then keeps using the name '[Module]' also everywhere else and so creates incorrect code.
Example of generated code:
As you can see, the property is correctly named '[Module]'. But then it also names the private variable '_[Module]' and creates a method 'AddTo[Module]', both times using faulty names.
The correct code should look like this:
			Backstory: Our method provider calls a collection of his 'Modulvariablen' a 'Modul'. The german plural of 'Modul' is 'Module'. Because we want to keep as close as possible to his naming schema this means a bit of trouble in Visual Basic, because 'Module' is also a language keyword. But you can work around that with using '[Module]' instead.
The ObjectContext template actually does this fine for the property declaration, but it then keeps using the name '[Module]' also everywhere else and so creates incorrect code.
Example of generated code:
Code: Select all
        ''' 
        ''' Gibt die Module zurück oder setzt diese.
        ''' 
        Public ReadOnly Property [Module]() As ObjectSet(Of Modul)
            Get
                If (_[Module] Is Nothing) Then
                    _[Module] = MyBase.CreateObjectSet(Of Modul)("Module")
                End If
                Return _[Module]
            End Get
        End Property
        Private _[Module] As ObjectSet(Of Modul)
        ''' 
        ''' Deprecated Method for adding a new object to the [Module] EntitySet.
        ''' 
        Public Sub AddTo[Module](modul As Modul)
            MyBase.AddObject("Module", modul)
        End SubThe correct code should look like this:
Code: Select all
        ''' 
        ''' Gibt die Module zurück oder setzt diese.
        ''' 
        Public ReadOnly Property [Module]() As ObjectSet(Of Modul)
            Get
                If (_Module Is Nothing) Then
                    _Module = MyBase.CreateObjectSet(Of Modul)("Module")
                End If
                Return _Module
            End Get
        End Property
        Private _Module As ObjectSet(Of Modul)
        ''' 
        ''' Deprecated Method for adding a new object to the [Module] EntitySet.
        ''' 
        Public Sub AddToModule(modul As Modul)
            MyBase.AddObject("Module", modul)
        End Sub