title: Pass an array of enums in C#
body: <p>I need to allow multiple roles to have access to a method, in a controller in C# Web api. </p>
  
  <p>I have a custom <code>AuthorizeAttribute</code> which takes an enum of role type, how can I make it so it accepts multiple enums ie. a variable length array of enums.</p>
  
  <p>This is the code I have written for the <code>Attribute</code>:</p>
  
  <pre><code>private readonly RoleEnum roleInApplication;
  
  public ScopeAuthorizeAttribute(RoleEnum roleInApplication)
  {
      this.roleInApplication = roleInApplication;
  }
  
  public override void OnAuthorization(HttpActionContext actionContext)
  {
      base.OnAuthorization(actionContext);
      .......
      var relatedPermisssionRole = (db call to get the rolename..etc)
      RoleEnum role;
      if (Enum.TryParse(relatedPermisssionRole, out role) &amp;&amp; role == roleInApplication)
      {
              // Succeed if the scope array contains the required scope
              return;
       }
    }
  
      HandleUnauthorizedRequest(actionContext);
  }
  </code></pre>
  
  <p>And in the controller, I use it like this:</p>
  
  <pre><code>[ScopeAuthorize(RoleEnum.ADMIN)]
  public async Task&lt;IHttpActionResult&gt; Create(MyModel model)
  </code></pre>
  
  <p>How do I allow multiple roles? eg.</p>
  
  <pre><code>[ScopeAuthorize(RoleEnum.ADMIN, RoleEnum.USER)]
  public async Task&lt;IHttpActionResult&gt; Create(MyModel model)
  </code></pre>