title: VB.Net CType Class to Enum
body: <p>I'm trying to create a class that can be CType'd to different types:</p>
  <pre><code>Option Strict Off
  
  Public Class CInteger
      Private Value As Integer
      Public Sub New(value As Integer)
          Me.Value = value
      End Sub
      Public Shared Widening Operator CType(ByVal value As CInteger) As Integer
          Return value.Value
      End Operator
      'Commenting next operator makes compilation without errors
      Public Shared Widening Operator CType(ByVal value As CInteger) As String
          Return value.Value
      End Operator
  End Class
  
  Public Enum EEnum1 As Integer
      First = 1
  End Enum
  Public Enum EEnum2 As Integer
      First = 1
  End Enum
  
  Private Sub Test()
      Dim e1 As EEnum1 = New CInteger(1)
      Dim e2 As EEnum2 = New CInteger(1)
  End Sub
  </code></pre>
  <p>It works fine converting to Enums if there's only and Integer operator defined, but when I try to add any other operator the compiler throws errors because the conversion can't be done.
  I can neither change the Enum declarations nor declare CType operator for each Enum, is it posible to workaround this?</p>