title: C# mimic overridding the assignment operator (=)
body: <p>I've got a bit of a problem with a somewhat simple wrapper class I have.</p>
  
  <p>It looks something like this:</p>
  
  <pre><code>public class Wrapper&lt;T&gt;
  {
    private T _value;
  
    public Wrapper&lt;T&gt;(T value)
    {
      _value = value;
    }
  
    public static implicit operator Wrapper&lt;T&gt;(T value)
    {
      return new Wrapper&lt;T&gt;(value);
    }
  
    public static implicit operator T(Wrapper&lt;T&gt; value)
    {
      return value._value;
    }
  }
  </code></pre>
  
  <p>I've overriden the implicit converters from and to T, so it behaves almost like an instance of T itself.</p>
  
  <p>e.g. </p>
  
  <pre><code>Wrapper&lt;int&gt; foo = 42;
  </code></pre>
  
  <p>However I've got a slight problem when assigning one instance of Wrapper to another, since I only want to assign the value of the second Wrapper class.</p>
  
  <p>So right now, I have to do this:</p>
  
  <pre><code>Wrapper&lt;int&gt; foo = 42;
  Wrapper&lt;int&gt; bar = (int)foo;
  </code></pre>
  
  <p>Or expose _value publicly through a property.</p>
  
  <p>However since this is in a library, and I don't want the user to depend on remembering this, do you guys have any idea how I could mimic overridding the assignment operator ?</p>
  
  <p>The problem in just changing the pointer (as it does when assigning a class instance to another), is that I've got a dictionary of pointers to these Wrapper objects, so I cannot have them changing all the time, since the dictionary would stop matching then.</p>
  
  <p>I can see if this is somewhat confusing, so if I've left anything important out, please feel free to ask :-)</p>