title: Attribute with action/condition
body: <p>Is it possible to specify achieve following:</p>
  
  <pre><code>[SomeAttribute(condition1)]
  public SomeType SomeSetting1 {get; set;}
  
  [SomeAttribute(condition2)]
  public SomeType SomeSetting2 {get; set;}
  </code></pre>
  
  <p>where <em>condition</em> is something <em>complicated</em>? To example,</p>
  
  <pre><code>[SomeAttribute(SomeSetting3 == 4 &amp;&amp; SomeSetting4 &lt; 100)]
  </code></pre>
  
  <hr>
  
  <p>I am using <code>PropertyGrid</code> to show/edit configuration as properties of some serializable class. And I need to have sort of <em>cascading</em>: when some setting is set, some others may be hidden, depending on the value.</p>
  
  <p>Currently, I can do hide some setting in this way:</p>
  
  <ul>
  <li>create new attribute, based on <code>IHide</code></li>
  <li>assign it to needed properties</li>
  <li><p>check all attributes for a given property in <code>ConfigWrapper</code>, if there is any of <code>IHide</code> type, then check its <code>Hide</code> to decide whenever show (add to result collection of properties) or not.</p>
  
  <pre><code>public interface IHide
  {
      bool Hide { get; }
  }
  
  public class AdminAttribute : Attribute, Common.IHide
  {
      public bool Hide
      {
          get { return !MySettings.Admin; }
      }
  
      public override object TypeId { get { return "AdminAttributeId"; } }
  }
  
  // admin only setting
  [Admin]
  public SomeType SomeSetting {get; set;}
  </code></pre></li>
  </ul>
  
  <p>This way I have to add a <strong>new attribute</strong> for any new setting (which have to hide some other settings) or combinations (and this is why I want something more <em>generic</em>). Of course sometimes I can use attribute parameter, to be able to use one attribute for several <em>similar</em> purposes:</p>
  
  <pre><code>public class ElementAttribute : Attribute, Common.IHide
  {
      private string _element;
      public bool Hide
      {
          get { return !Something.Instance.IsElement(_element); }
      }
  
      public ElementAttribute(string element)
      {
          _element = element;
      }
  
      public override object TypeId { get { return "ElementAttributeId"; } }
  }
  </code></pre>
  
  <p>By using this attribute, I can specify element symbol:</p>
  
  <pre><code> // setting will be shown if element a present
   [Element('a')]
   public SomeType SomeSetting {get; set;}
  </code></pre>
  
  <p>After creating multiple of such, I came to idea what maybe it is possible somehow to <em>code</em> that <code>Hide()</code> method condition into the attribute parameter itself??? Or perhaps specify behavior (action) somehow? </p>
  
  <p>I can pretty easily do it by using <code>CodeDom</code> me think, but it would be very sloooooow. It is possible to enumerate all attributes and cache conditions. But maybe there is an easier/alternative way? Any other ideas?</p>
  
  <h2>Starting bounty</h2>
  
  <p>I am searching for ideas to combine multiple <code>IHide</code> attributes (<code>AdminAttribute</code> - show settings when user is admin, <code>ElementAttribute</code> - show setting when specified element presents, etc.) into a single <em>super-attribute</em>. I want to be able to specify conditions somehow, without the need to create new <code>IHide</code> based attribute for <strong>every case</strong>.</p>
  
  <p>What would be your solution if you have to handle hundreds of settings (which are existing at once), but with relations between each other and additionally related on some other conditions? How to create <code>Admin</code> and <code>Element</code> attribute behavior without creating <code>AdminAttribute</code> and <code>ElementAttribute</code>?</p>
  
  <p>The point is, what there are multiple different configurations (inherited from base configuration) and I want to be able in some of them freely specify visibility conditions with a part of code, which, if evaluates into false, will hide the setting, without creating dozens of <code>IHide</code> based attributes. Sort of declarative programming when defining the setting itself!</p>