Where should I put my global constants in the .NET library?

I work with an API that spills out a lot of data in the format name = value. At first I processed everything, doing simple string comparisons:

Sub ProcessData(ByVal name As String, ByVal value As String)
    If name = "thisname" Then
        DoThis(value)
    ElseIf name = "thatname" Then
        DoThat(value)
    End If
End Sub

But with over 20 different possible names for processing, it quickly became difficult to maintain. My next step was to move the lines to the constants defined in the private subclass:

 Private Class Parameters
     Private Sub New()
     End Sub

     Public Const ThisName As String = "thisname"
     Public Const ThatName As String = "thatname"

 End Class

And my method would look like this:

    Sub ProcessData(ByVal name As String, ByVal value As String)
        If name = Parameters.ThisName Then
            DoThis(value)
        ElseIf name = Parameters.ThatName Then
            DoThat(value)
        End If
    End Sub

This was a huge step forward, but now I was in a position where I needed to use these constants in other classes. I hesitate to move them to a global class, but I just do not see another option.

Where do global constants go?

+3
source share
2 answers

. , .
, .
, , , .
, XML .

+4

. , IL. , , , , . .

Public constant, ReadOnly.

+5

All Articles