WinForms デザイナーの一部のコントロールに Type プロパティを追加しようとしています。typeof(MyCompany.TheTypeIUsed) を使用してシリアル化するのが理想的です (BindingSource.DataSource をシリアル化できる方法)。
タイプのデザイナーを指定していないという事実はさておき、「タイプ」を使用する IExtenderProvider を追加すると、プロパティはプロパティ グリッドに表示されないようです。int または string またはその他の型を使用すると、正常に動作します。
これは IExtenderProvider 実装のバグですか、それとも追加の属性などが必要ですか?
[ProvideProperty("CommandType", typeof (Control))]
public class TypeExtender : Component, IExtenderProvider
{
private readonly Dictionary<Control, Type> controlCommands;
public TypeExtender()
{
controlCommands = new Dictionary<Control, Type>();
}
#region impl
bool IExtenderProvider.CanExtend(object target)
{
var control = target as Control;
if (control == null)
{
return false;
}
return true;
}
[DefaultValue(null)]
public Type GetCommandType(Control obj)
{
if (obj == null)
{
Debug.Fail("Non Control provided to Type getter");
return null;
}
Type commandType;
if (controlCommands.TryGetValue(obj, out commandType))
{
return commandType;
}
return null;
}
public void SetCommandType(Control obj, Type value)
{
if (obj == null)
{
Debug.Fail("Non control provided to Command Setter");
return;
}
if (value == null)
{
controlCommands.Remove(obj);
}
else
{
controlCommands[obj] = value;
}
}
[UsedImplicitly]
private bool ShouldSerializeCommand(object c)
{
var control = c as Control;
if (control == null)
{
return false;
}
Type type;
if (controlCommands.TryGetValue(control, out type))
{
return type != null;
}
return false;
}
[UsedImplicitly]
private void ResetCommand(object c)
{
if (c is Control)
{
controlCommands.Remove(c as Control);
}
}
#endregion
}