可以在智能感知或设计视图中显示Nullable Enum值

jba*_*bey 2 vb.net asp.net intellisense enums custom-controls

我正在开发一个自定义用户控件.用户控件具有映射到枚举的属性,不应具有任何默认值,即控件的使用者必须设置它.

财产:

<Description("This is the property description"),
Category("SomeCategory"), Bindable(True)>
Public Property SomeProperty As Enumerations.SomeEnumeration?
Run Code Online (Sandbox Code Playgroud)

枚举:

Namespace Enumerations
    Public Enum SomeEnumeration
        Zero = 0
        One
        Two
    End Enum
End Namespace
Run Code Online (Sandbox Code Playgroud)

支票:

If SomeProperty Is Nothing Then
    Throw New ApplicationException("You must set SomeProperty.")
End If
Run Code Online (Sandbox Code Playgroud)

问题:

所有的逻辑都有效.我的问题是当你尝试SomeProperty 从标记设置时,没有任何枚举值出现在intellisense中.我的一位同事发现了这个相关的支持请求,因此它似乎是一个已知问题.

我的问题是,支持此控件所需的所有行为的最佳方法是什么,以及在此属性上保持智能感知?

Cha*_*nns 5

我可以重新创建这个问题 - 使枚举可以为空使智能感知停止工作.我想这是因为可空类型是对象.

建议将枚举保持为不可为空.默认值为NotSetNone.如果未设置枚举,则可以在getter或初始化代码中引发异常.

属性

<Description("This is the property description"),
Category("SomeCategory"), Bindable(True)>
Public Property SomeProperty As Enumerations.SomeEnumeration
Run Code Online (Sandbox Code Playgroud)

列举

Namespace Enumerations
    Public Enum SomeEnumeration
        NotSet = -1
        Zero = 0
        One
        Two
    End Enum
End Namespace
Run Code Online (Sandbox Code Playgroud)

校验

If SomeProperty Is SomeProperty.NotSet Then
    Throw New ApplicationException("You must set SomeProperty.")
End If
Run Code Online (Sandbox Code Playgroud)