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).
I have an IExtenderProvider component that I'm using to have my own UITypeEditor for some properties on third-party controls (which I can't change, for obvious reasons).
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).
So, imagine for example I want to make an alternative property for the properties Image, Glyph, LargeGlyph, SmallGlyph on them.
So I have something like:
[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 => t.IsInstanceOfType(o));
}
// Implement the property setter and getter methods
}
So far, so good. I can see my properties on the controls of the types I'm expecting.
However, these are replacements (just to change the UITypeEditor) of properties in the control.
The problem with my approach is that I see all of the extended properties in all of the extended types.
Say, if AButton only has Image, I only want to see ImageCustom and not SmallImageCustom, LargeImageCustom, etc.
So my approach was to do this:
[ProvideProperty("LargeGlyphCustom", typeof (OtherControl))]
// other properties
[ProvideProperty("ImageCustom", typeof(AButton))]
public class MyImageExtender : Component, IExtenderProvider
// ...
This seemed to work fine, and now I only see ImageCustom on AButton, and LargeGlyphCustom on OtherControl.
Now the problem is, if I want to show ImageCustom in both AButton and OtherControl, I had thought of doing this:
[ProvideProperty("ImageCustom", typeof(AButton))]
[ProvideProperty("ImageCustom", typeof(OtherControl))]
public class MyImageExtender : Component, IExtenderProvider
This doesn't work though, I only get to see ImageCustom on AButton, but not on OtherControl.
Decompiling the sources for ProvidePropertyAttribute, the reason this happens is "arguably" clear. It internally creates a TypeId, which I suspect is what the WinForms designer is using like this:
public override object TypeId
{
get
{
return (object) (this.GetType().FullName + this.propertyName);
}
}
Which makes the TypeId be "ProvidePropertyAttributeImageCustom", so it can't differentiate between the different receiver types.
I'm going to test deriving ProvidePropertyAttribute and create a different TypeId since it seems overridable, but I expect the winforms designer expect the specific ProvidePropertyAttribute type and not a derived one (the winforms designer is picky with these things).
Ouch, ProvidePropertyAttribute is sealed so I can't derive and make my custom TypeId, it seems (not that I had high hopes that this would work at all)
In the meantime, anyone has ever done something like this and know something I could use?