Q:

How can I create an "enum" type property value dynamically

I need to create a property in a class that will give the programmer a list of values to choose from. I have done this in the past using the enums type.
Public Enum FileType
    Sales
    SalesOldType
End Enum

Public Property ServiceID() As enFileType
    Get
        Return m_enFileType
    End Get
    Set(ByVal value As enenFileType)
        m_enFileType = value
    End Set
End Property

The problem is I would like to populate the list of values on init of the class based on SQL table values. From what I have read it is not possible to create the enums on the fly since they are basically constants. 
Is there a way I can accomplish my goal possibly using list or dictionary types?
OR any other method that may work.

A:

If the values aren't going to change after the code is compiled, then it sounds like the best option is to simply auto-generate the code.  For instance, you could write a simple application that does something like this:
Public Shared Sub Main()
    Dim builder As New StringBuilder()
    builder.AppendLine("' Auto-generated code.  Don't touch!!  Any changes will be automatically overwritten.")
    builder.AppendLine("Public Enum FileType")
    For Each pair As KeyValuePair(Of String, Integer) In GetFileTypesFromDb()
        builder.AppendLine(String.Format("    {0} = {1}", pair.Key, pair.Value))
    End For
    builder.AppendLine("End Enum")
    File.WriteAllText("FileTypes.vb", builder.ToString())
End Sub

Public Function GetFileTypesFromDb() As Dictionary(Of String, Integer)
    '...
End Function

Then, you could add that application as a pre-build step in your project so that it automatically runs each time you compile your main application.

