ok, so I want to create a generic class that will change the value of a data type. The reason I want to do this is because I can use undo and redo methods. I could write a class for every important type that I need. I.E. double, int ... but it would be much simpler if I could create a generic class for this.
This is what I have
class CommandChangeDouble : Command { double _previous; double _new; double* _objectRef; public unsafe CommandChangeDouble(double* o, double to) { _objectRef = o; _previous = *o; _new = to; *_objectRef = _new; } public unsafe void Undo() { *_objectRef = _previous; } public unsafe void Redo() { *_objectRef = _new; } }
this is what i want
class CommandChangeValue<T> : Command { T _previous; T _new; T* _objectRef; public unsafe CommandChangeValue(T* o, T to) { _objectRef = o; _previous = *o; _new = to; *_objectRef = _new; } public unsafe void Undo() { *_objectRef = _previous; } public unsafe void Redo() { *_objectRef = _new; } }
but it gives me the error Error "Unable to accept address, get size or declare a pointer to a managed type (" T ")"
Is there a better way to do this or a way around this error?
generics pointers c # value-type
Daniel Johnson Jun 17 '13 at 20:23 2013-06-17 20:23
source share