DarkRift
DarkRift copied to clipboard
`DarkRiftWriter` does not hold type safety.
Thanks for creating an issue/feature request! Please use the template below to ensure you have all the necessary information.
Quick Description
DarkRiftWriter.Write<T>(T value) : where T : IDarkRiftSerializable
does not hold type safety.
Explaination
Generic type constraints are not part of the method signature, as such, using a where
clause does not hold type safety when creating Extension Methods
for DarkRiftWriter
.
Reproduction
Create an extension method for DarkRiftWriter & try to compile.
Possible solution:
Revert back to the type safe DarkRiftWriter.Write(IDarkRiftSerializable serializable)
Firstly, thanks for raising this as an issue! 🙂
I didn't realise type constraints weren't part of the method signature when this was implemented, which makes this rather annoying.
Realistically, removing this would break backwards compatibility (although, only requiring recompilation not any code changes) but more importantly the reason this was added was to avoid the boxing of IDarkRiftSerializable structs when added so really needs to stay present (I'm aiming for sending/receiving to be completely garbage free). Ultimately, I don't think just removing it is the best solution.
This shouldn't stop other extension methods being created however, it just means they can't have the name Write
which, while a shame, isn't the end of the world.
I'd certainly welcome any thoughts you have!
Well, one way to go around this (which is what I'm doing at the moment) is by using Named Parameters
, this eliminates having different function names & is generally still good practice anyway.
Probably not the best of practices in this particular case, but it's better than breaking the naming convention, I assume. It still feels a bit hacky to me though, I'll be getting back to it sometime soon and will let you know what else I come up with! :)
Also, most welcome!