title: Using LINQ and Reflection: How to query for all Classes with [Authorize] Attribute in my Assembly?
body: <p>Currently, I'm trying to identify which "Controller" classes in my assembly have the [Authorize] attribute associated with them using Reflection and LINQ.</p>
  
  <pre><code>const bool allInherited = true;
  var myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
  var controllerList = from type in myAssembly.GetTypes()
                       where type.Name.Contains("Controller")
                       where !type.IsAbstract
                       let attribs = type.GetCustomAttributes(allInherited)
                       where attribs.Contains("Authorize")
                       select type;
  controllerList.ToList();
  </code></pre>
  
  <p>This code almost works.</p>
  
  <p>If I trace through the LINQ statement step-by-step, I can see that when I "mouseover" the "attribs" range variable that I define in the LINQ statement is populated with a single Attribute and that attribute happens to be of type AuthorizeAttribute. It looks sort of like this:</p>
  
  <pre><code>[-] attribs | {object[1]}
     [+]  [0] | {System.Web.Mvc.AuthorizeAttribute}
  </code></pre>
  
  <p>Clearly, this line in my LINQ statement is wrong:</p>
  
  <pre><code>where attribs.Contains("Authorize")
  </code></pre>
  
  <p>What should I write there instead to detect if "attribs" contains the AuthorizeAttribute type or not? </p>