title: Check if element has attribute
body: <p>I'm trying to create extension method that checks if specific object has specific attribute.</p>
  
  <p>I've found example that checks it with the following syntax:</p>
  
  <pre><code>private static bool IsMemberTested(MemberInfo member)
  {
  foreach (object attribute in member.GetCustomAttributes(true))
      {
          if (attribute is IsTestedAttribute)
          {
             return true;
          }
      }
  return false;
  }
  </code></pre>
  
  <p>Now I'm trying to do the following:</p>
  
  <pre><code>    public static bool HasAttribute&lt;T&gt;(this T instance, Type attribute)
      {
          return typeof(T).GetCustomAttributes(true).Any(x =&gt; x is attribute);
      }
  </code></pre>
  
  <p>However I get the message 'The type or namespace 'attribute' is missing...'</p>
  
  <p>What am I doing wrong and different from given example / how can I make this happen?</p>
  
  <p>EDIT: </p>
  
  <p>Thanks for the tips, I've managed to do it like this now:</p>
  
  <pre><code>    public static bool HasAttribute&lt;T&gt;(this T instance, Type attribute)
      {
          return typeof(T).GetCustomAttributes(attribute, true).Any();
      }
  </code></pre>
  
  <p>And checking for attribute goes like this:</p>
  
  <pre><code>var cc = new CustomClass();
  var nullable = cc.HasAttribute(typeof(NullableAttribute));
  </code></pre>
  
  <p>Thanks for help guys. Now I have another question. Say I want to decorate a property of the class, property of type string, with an attribute, and want to check later on if that property has an attribute. Since this works only with types, I can't apply it on property level. Is there any solution to property check?</p>