有没有办法做这样的事情?
Public Enum CarMakes
Honda
BMW
Mazda
Friend Yugo
End Enum
我需要将Enum暴露给公众,除了我想要从程序集中提供的其中一个项目。
答案 0 :(得分:1)
这是不可能的。单个枚举值没有可访问性的概念,而只是具有声明枚举的可访问性。
注意:即使他们确实具有可访问性,呼叫者也很容易违反它。不检查枚举值的正确性。因此,即使上述语法合法,我也可以通过以下方式颠覆它。
' Yugo has the numeric value 3 due to it's declaration location
Dim carMakes As CarMakes = 3
' CarMakes can be any Integer value. Even ones which have no mapping
' to the values you've defined
Dim other As CarMakes = 1042
这将编译并运行,没有任何错误,并产生可验证的IL。