N
Nio
Hello, I have a class implementing comparison operators and cast operators
(CType) .
This class called MyOpTest
Now look at this code:
Dim MyOp As New MyOpTest
Dim data As String = MyOp 'OK no error, MyOpTest
implements "Shared narrowing operator CType(byval a As MyOpTest) As String"
Dim obj As Object = New MyOpTest 'now instance is boxed into an
object type
Dim Result as Boolean = Cbool(obj < 2) 'OK no error MyOpTest implements
"Shared operator < (byval p1 as Object, byval p2 As Object) As Boolean"
Dim data2 As String = obj 'This failed!! casting
exception from MyOpTest!! to String
So why when instance is boxed into object, casting operations are not called
and comparison operators are called ?
Is there any solution ? (a way to implicit unbox object type) ?
Thanks for your answers.
(CType) .
This class called MyOpTest
Now look at this code:
Dim MyOp As New MyOpTest
Dim data As String = MyOp 'OK no error, MyOpTest
implements "Shared narrowing operator CType(byval a As MyOpTest) As String"
Dim obj As Object = New MyOpTest 'now instance is boxed into an
object type
Dim Result as Boolean = Cbool(obj < 2) 'OK no error MyOpTest implements
"Shared operator < (byval p1 as Object, byval p2 As Object) As Boolean"
Dim data2 As String = obj 'This failed!! casting
exception from MyOpTest!! to String
So why when instance is boxed into object, casting operations are not called
and comparison operators are called ?
Is there any solution ? (a way to implicit unbox object type) ?
Thanks for your answers.