У меня есть класс с именем Foo
с такими свойствами:
Public Class Foo(Of T)
public Property Value as T
public Property Bar as Boolean
End Class
У меня перегрузка функции преобразования типов:
Public Shared Narrowing Operator CType(ins As [Foo](Of T)) As T
Return ins.Value
End Operator
Public Shared Widening Operator CType(prop As T) As [Foo](Of T)
Return New Foo(Of T) With {.Value = prop}
End Operator
Я использую свой класс следующим образом:
private Sub someSub()
Dim f as new Foo(of String)
f.Bar = True
f = "This is The Text"
// when doing this I lose the `Bar` beacuase of `Return New Foo(Of T) With {.Value = rightSide}` on `Widening` overload
End Sub
есть ли способ сохранить другие свойства класса?