Closed JechoJekov closed 9 years ago
Since a serializable type cannot be verified perhaps a suitable approach would be to permit casing of any serializable type to any other serializable type which by the way is already permitted when used with direct casting:
var otherObj = (OtherType)(object)myObj;
The ss.cast method can perform a check like this: if the target type is a serializable type and the object being cast is serializable then permit the casting.
Casting a serializable object to its own type causes a "Cannot cast object to type ..." exception when the type is used with a generics method (which is often the case with LINQ's 'Cast' method).
The code below results in a "Cannot cast object to type Test.App.$SerA" exception.