title: How to get a list of properties with a given attribute?
body: <p>I have a type, <code>t</code>, and I would like to get a list of the public properties that have the attribute <code>MyAttribute</code>. The attribute is marked with <code>AllowMultiple = false</code>, like this:</p>
  
  <pre><code>[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
  </code></pre>
  
  <p>Currently what I have is this, but I'm thinking there is a better way:</p>
  
  <pre><code>foreach (PropertyInfo prop in t.GetProperties())
  {
      object[] attributes = prop.GetCustomAttributes(typeof(MyAttribute), true);
      if (attributes.Length == 1)
      {
           //Property with my custom attribute
      }
  }
  </code></pre>
  
  <p>How can I improve this? My apologies if this is a duplicate, there are a ton of reflection threads out there...seems like it's quite a hot topic.</p>