Is there any good way to create a generic Vector4 class in C#? I have a couple of units(force, distance, moment, rotation, acceleration, velocity etc) that all need a 3d-representation and they all behave very similar and should therefore support the basic functions for adding, multiplying etc.
Each class also contain some special cases, for example force⨯distance=moment. Therefore i want to be able to create a Force3d inheriting from Vector4<Force>
so i don't have to write all those arrows all the time and to be able to add these force-specific functions to the struct.
I've been using this inherit-based approach, where every unit inherits from Vector4, until now but this causes some problems because when i for example call Add(force1, force2) i get the baseclass, Vector4, back instead of a Force3d. So i end up either casting or creating a copy of the Add-function for every unit.
I want to be able to create both a Vector4<double>
and a Vector4<Force>
without having to redefine all basic functions for adding, multiplying etc(preferably with the real operators, which seems impossible). This also adds some new problems because the best solution would be to make Force inherit from double but since all base types are sealed i have to create a containerclass and i end up redefining the basic operators for numbers here instead.
I've been trying every approach possible but i always end up redefining way too much stuff.