title: IExtenderProvider add just some properties depending on object type
body: <p>I'm having an issue and I don't know if this is indeed doable (if there's a "hacky" way, I'm all up for it, but I haven't found one).</p>
  
  <p>I have an <code>IExtenderProvider</code> component that I'm using to have my own <code>UITypeEditor</code> for some properties on third-party controls (which I can't change, for obvious reasons).</p>
  
  <p>These controls don't necessarily inherit from the same base (and if they do, the base doesn't necessarily have the properties I want to extend, and those are defined in the same class).</p>
  
  <p>So, imagine for example I want to make an alternative property for the properties <code>Image</code>, <code>Glyph</code>, <code>LargeGlyph</code>, <code>SmallGlyph</code> on them.</p>
  
  <p>So I have something like:</p>
  
  <pre><code>[ProvideProperty("LargeGlyphCustom", typeof (object))]
  [ProvideProperty("GlyphCustom", typeof(object))]
  [ProvideProperty("SmallImageCustom", typeof(object))]
  [ProvideProperty("LargeImageCustom", typeof(object))]
  [ProvideProperty("ImageCustom", typeof(object))]
  public class MyImageExtender : Component, IExtenderProvider
  {
    private readonly Type[] _extendedTypes =
    {
      typeof (OtherControl),
      typeof (SomeOtherControl),
      typeof (AControl),
      typeof (AButton)
    };
  
    bool IExtenderProvider.CanExtend(object o)
    {
      if (!DesignMode) return false;
      return _extendedTypes.Any(t =&gt; t.IsInstanceOfType(o));
    } 
  
    // Implement the property setter and getter methods
  }
  </code></pre>
  
  <p>So far, so good. I can see my properties on the controls of the types I'm expecting.</p>
  
  <p>However, these are replacements (just to change the <code>UITypeEditor</code>) of properties in the control.</p>
  
  <p>The problem with my approach is that I see <strong>all</strong> of the extended properties in <strong>all</strong> of the extended types.</p>
  
  <p>Say, if <code>AButton</code> only has <code>Image</code>, I only want to see <code>ImageCustom</code> and not <code>SmallImageCustom</code>, <code>LargeImageCustom</code>, etc.</p>
  
  <p>So my approach was to do this:</p>
  
  <pre><code>[ProvideProperty("LargeGlyphCustom", typeof (OtherControl))]
  // other properties
  [ProvideProperty("ImageCustom", typeof(AButton))]
  public class MyImageExtender : Component, IExtenderProvider
  // ...
  </code></pre>
  
  <p>This seemed to work fine, and now I only see <code>ImageCustom</code> on <code>AButton</code>, and <code>LargeGlyphCustom</code> on <code>OtherControl</code>.</p>
  
  <p>Now the problem is, if I want to show <code>ImageCustom</code> in both <code>AButton</code> and <code>OtherControl</code>, I had thought of doing this:</p>
  
  <pre><code>[ProvideProperty("ImageCustom", typeof(AButton))]
  [ProvideProperty("ImageCustom", typeof(OtherControl))]
  public class MyImageExtender : Component, IExtenderProvider
  </code></pre>
  
  <p>This doesn't work though, I only get to see <code>ImageCustom</code> on <code>AButton</code>, but not on <code>OtherControl</code>.</p>
  
  <p>Decompiling the sources for <code>ProvidePropertyAttribute</code>, the reason this happens is "arguably" clear. It internally creates a <code>TypeId</code>, which I <em>suspect</em> is what the WinForms designer is using like this:</p>
  
  <pre><code>public override object TypeId
  {
    get
    {
      return (object) (this.GetType().FullName + this.propertyName);
    }
  }
  </code></pre>
  
  <p>Which makes the TypeId be <code>"ProvidePropertyAttributeImageCustom"</code>, so it can't differentiate between the different receiver types.</p>
  
  <p><s>I'm going to test deriving <code>ProvidePropertyAttribute</code> and create a different <code>TypeId</code> since it seems overridable, but I expect the winforms designer expect the specific <code>ProvidePropertyAttribute</code> type and not a derived one (the winforms designer is picky with these things).</s></p>
  
  <p>Ouch, <code>ProvidePropertyAttribute</code> is <code>sealed</code> so I can't derive and make my custom <code>TypeId</code>, it seems (not that I had high hopes that this would work at all)</p>
  
  <p>In the meantime, anyone has ever done something like this and know something I could use?</p>