Understanding CLS Compliance and Correct Code

I tried to create an abstract control to control some state in our application. However, I ran into some CLS issues and was hoping that someone could give some insight.

I have an enumeration as such:

<Flags()> _
Public Enum FormState
    Read = 1
    Edit = 2
    Insert = 4
End Enum

And the class itself:

Public MustInherit Class Fields
    Inherits System.Web.UI.UserControl

    Public Property State() As Enumerators.FormState
        Get
            Return _State
        End Get

        Set(ByVal value As Enumerators.FormState)
            _State = value
            ToggleState(value)
        End Set
    End Property

    Protected MustOverride Sub ToggleState(ByVal state As FormState)
End Class

When I try to compile this code, I leave a warning that the State property is not CLS-compatible and is not a state argument. How so? And how can I fix this problem to remove warnings?

  • I tried adding the <CLSCompliant (True)> attribute to both elements with no luck
  • MSDN "MustOverride" , CLS, CLS-
  • Friend Public
  • Enum (Integer UInteger)
+3
3

, , , enumerators. , , .

CLS.

+5

, , , :

<CLSCompliant(False)> _
Public MustInherit Class Fields
    Inherits System.Web.UI.UserControl

    <CLSCompliant(False)> _
    Public Property State() As Enumerators.FormState
        Get
            Return _State
        End Get

        Set(ByVal value As Enumerators.FormState)
            _State = value
            ToggleState(value)
        End Set
    End Property

    <CLSCompliant(False)> _
    Protected MustOverride Sub ToggleState(ByVal state As FormState)
End Class

, , CLSCompliant.

+1

, 0.

0

Source: https://habr.com/ru/post/1703387/


All Articles