Question

I used to have a Public class with around 1800 Public Shared Strings in it - kinda like my constants library:

Public Shared ReadOnly NLS_ALREADY_IN_USE_QUERYNAME As String = "AlreadyInUseQueryName"

Now I want to store a little more info for each element and change them to "As MyClass" with an appropriate constructor that takes the String from my previously used definition:

Public Shared ReadOnly NLS_ALREADY_IN_USE_QUERYNAME As QNLSDefinition = New QNLSDefinition("AlreadyInUseQueryName", "Deutsch", "English")

The problem is that these "objects" are not instantiated automatically although they are Shared. String obviously is "immediately instantiated".

Any best practise around for this?

Was it helpful?

Solution

You can create a Constructor for that Class and you instantiate all Static variables there in your contructor just one time in your application:

Class Constants 

   Public Shared ReadOnly NLS_ALREADY_IN_USE_QUERYNAME As QNLSDefinition

   'Constructor
   Sub New()

      NLS_ALREADY_IN_USE_QUERYNAME = New QNLSDefinition("AlreadyInUseQueryName",  "Deutsch", "English")

   End Sub

End Class

And then you go to your application constructor

Sub New()
   InitializeComponent()
   'Instantiate shared variables
   Dim const as new Constants
 End Sub()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top