General

Error:

"WithEvents" can only be enter classes, interfaces or type parameters with class restrictions

Background:

Public Class Tadpole(Of T As IVisibleChanged, P As IVisibleChanged)
  Private WithEvents _Tad As T ' ERROR '
  Private WithEvents _Pole As P ' ERROR '

  Public Property Tad() As T ...

  Public Property Pole() As P ...

End Class

''' IVisibleChanged '''
Public Interface IVisibleChanged
  Property Visible() As Boolean
  Event VisibleChanged As EventHandler
End Interface

Workaround:

and. Use AddHandlerto handle events defined in the structure.

EDIT

b. use (M.A. Khanin)Private WithEvents _Tad As IVisibleChanged

with.

+3
source share
1 answer

I suspect this is because WithEvents does not support value types. When you only restrict T to be IVisibleChanged, you are not guaranteeing a reference type, so WithEvents cannot be used. I do not know the syntax of VB, but if it looks like C #, you could do:

' Not sure of the VB syntax.
(Of T As {IVisibleChanged, Class})

, T IVisibleChanged, .

+3

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


All Articles