title: C# flag enum toggle by value or name
body: <p>I have a Flags <code>enum</code> and would like to toggle some values by its (<code>long</code>) value.</p>
  
  <pre><code>[Flags]
  public enum Permissions : long
  {
      Value0 = 0,
      Value1 = 0x1,
      Value2 = 0x2,
      Value3 = 0x4,
      //etc
  }
  </code></pre>
  
  <p>I store the actual permission in the database by <code>EF</code> using a <code>long</code> field, eg:</p>
  
  <pre><code>   public Permissions UsersPermissions { get; set; }
  </code></pre>
  
  <p>From the client side I get values one by one to toggle the proper value by <code>enum</code>, so if the database field contains </p>
  
  <pre><code>`Value1 | Value2 | Value3`
  </code></pre>
  
  <p>and I get a 4 I have to remove Value3 from the user's permissions.</p>
  
  <ul>
  <li>How can I get the proper <code>enum</code> value by its long version?</li>
  <li>How can I switch one value in UserPermissions field by its long representation?</li>
  </ul>
  
  <p>I have tried <code>usersPermissions |= permissionValue</code> but it says I can not use the <code>|=</code> operator on <code>long</code> and <code>Permission</code> Types.</p>