Define String ENUM in VB.Net

后端 未结 6 1605
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 15:37

I am using Window Application for my project. There is situation where i need to define string enum and using it in my project.

i.e.

Dim PersonalInfo         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-09 16:25

    I know this is an old post put I found a nice solution that worth sharing:

    ''' 
    ''' Gives acces to strings paths that are used often in the application
    ''' 
    Public NotInheritable Class Link        
        Public Const lrAutoSpeed As String          = "scVirtualMaster<.lrAutoSpeed>"
        Public Const eSimpleStatus As String        = "scMachineControl<.eSimpleStatus>"
        Public Const xLivebitHMI As String          = "scMachineControl<.xLivebitHMI>"      
        Public Const xChangeCycleActive As String   = "scMachineControl<.xChangeCycleActive>"
    
    End Class
    

    Usage:

    'Can be anywhere in you applicaiton:
    Link.xChangeCycleActive
    

    This prevents unwanted extra coding, it's easy to maintain and I think this minimizes extra processor overhead.

    Also visual studio shows the string attributes right after you type "Link" just like if it is a regular Enum

提交回复
热议问题