title: Using a bitfield for more readable code
body: <p>I'm working on a legacy web application written in .NET. At the start of the application it checks for which user type is logged in and determines which UI elements to display based on the user type.</p>
  
  <p>The way this is implemented now is a series of if statements to handle each user type case followed by a function call to set the various UI elements to either visible or invisible based on the user type.  The problem is the function call is kind of messy.  There are about 500 lines of the following:</p>
  
  <pre><code>setTabsVisible(true, true, true, true, true, true, true, true, true, true, false, false);
  if (!locked)
  {
      setActionButtonsVisibile(true, false, true, "Submit", "");
      script += setTabsReadOnly(false, false, false, false, false, false, true, false, false, false, true, true);
      script += setSubTabsReadOnly(true, true, false, true, true, true, false, false, true, true, false, true);
  }
  script += setSubTabsVisible(false, false, false, false, false, false, true, false, false, true, true);
  </code></pre>
  
  <p>All that true, true, false, true, etc isn't very readable at first glance.  To see what's being turned on or off you have to hover over the function and match up boolean values to the parameter list.</p>
  
  <p>So I was thinking a better solution might be a bit field that is built from constants that are bitwise OR'd together.  This way a function call might look more like this:</p>
  
  <pre><code>setTabsReadOnly(notesTab | documentsTab | signoffTab | etc);
  </code></pre>
  
  <p>However, C# doesn't seem to have support for bitfields.  Is there a better solution?  Or is it even worth changing?</p>