开发者

How do I limit the posible options to be assign to a .net property

开发者 https://www.devze.com 2022-12-29 01:56 出处:网络
Hello how can I have like a catalog for a property in .net VB .. I mean if i have 开发者_运维百科

Hello how can I have like a catalog for a property in .net VB .. I mean if i have

开发者_运维百科
Property funcion(ByVal _funcion As Int16) As Int16 
    Get
        Return _funcion
    End Get

    Set(ByVal value As Int16)
        _funcion = value
    End Set
End Property

I want to be able to assign to this property a limited number of options.

Example ..

Dim a as trick
a.funcion = (and get a list of possible attributes) ...

Thanks !!!


Instead of having it be of type Int16 have it be an Enum. It won't be perfect since someone could still get around it, but they'd have to make an effort.

Here's the documentation for Enum:

http://msdn.microsoft.com/en-us/library/8h84wky1%28VS.80%29.aspx


Set(ByVal value As Int16)
    If value < 0
        Throw New ArgumentException("value must be greater than or equal to 0")
    _funcion = value
End Set

There is also compile-time checking for this in VS 2010 (though it requires VS 2010 Professional or greater).

Example usage:

''VB.Net 10 / Visual Studio 2010 Professional only
Set(ByVal value As Int16)
    Contract.Requires(value >= 0)
    _funcion = value
End Set


Here is how it ended ...

Enum _funciont As Short
          Full = 1
          Table = 2
          Login = 3
End Enum

Property funcion() As _funciont  

            Get
                Return CType(_funcion, _funciont)
            End Get

            Set(ByVal value As _funciont)
                _funcion = value
            End Set
        End Property

Then when i put a s.funcion = ... get the list like a combo box .. !! thanks ...

0

精彩评论

暂无评论...
验证码 换一张
取 消