title: Pointers of generic type?
body: <p>ok so i want to make a generic class that will change the value of a datatype. The reason i want to do this is so i can have undo and redo methods. I could write a class for each valuetype i need. I.E. double, int... but it would be much easier if i could create a generic class to do this.</p>
  
  <p>This is what i have</p>
  
  <pre><code>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;
      }
  }
  </code></pre>
  
  <p>this is what i want</p>
  
  <pre><code>class CommandChangeValue&lt;T&gt; : 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;
      }
  }
  </code></pre>
  
  <p>but this gives me the error Error "Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')"</p>
  
  <p>Is there a better way to do this or a way to get around this error?</p>