You added (an object) to make the compiler stop telling you that you are doing it wrong. This worked, the compiler can no longer complain because it does not allow type checking. And casting from object to T can really work as much as possible.
What you did not expect, however, is that explicit conversion operators are C # language. Only the compiler knows which method to execute when such a cast is applied. This is not a CLR function; the runtime does not go hunting and collecting in order to try to find an applicable method for conversion. The C # compiler is otherwise powerless to use any of the operators that you provided at compile time, it does not know the type T.
The problem is that the compiler no longer helps when casting is done. Kaboom.
Having generic types used at runtime instead of compile time is a .NET function, the general term is βreified genericsβ. In contrast to "type erasure," how generic tools are implemented in Java and C ++. The problem with type-erasing is that all information about type-type arguments is lost after compiling the code, the general type cannot be used in another language, and Reflection does not work. The problem with generic generics is that operations that cannot be applied universally to any type cannot be used. Like the operator + (). And like that.
source share