Hello,
I have a Component witth the following field
[DefaultValue(null)]
[TypeConverter(typeof(HandlerConverter))]
public EventHandler Handler
{
get { return handler; }
set { handler = value; }
}
in the TypeConverter I try to Create a delagate but it failed with ArgumentException
public
override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value){
if (value is string)
{
object res = null;
try
{
IDesignerHost host = (IDesignerHost)context.Container;
MethodInfo m = Type.GetType(host.RootComponentClassName).GetMethod((string)value, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (m != null)
return Delegate.CreateDelegate(typeof(EventHandler), host.RootComponent, m, false);
m = Type.GetType(host.RootComponentClassName).GetMethod((string)value, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
if (m != null)
return Delegate.CreateDelegate(typeof(EventHandler), m, false);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(string.Format(" Failed to Convert exception: {0} \n {1} \n {2} ", e.GetType().FullName, e.Message, e.StackTrace));
}
return res;
}
return base.ConvertFrom(context, culture, value);
}
The methodInfo is containing the good information but the CreateDelagate failed
How can I do I wouldn't like to create an event because the event didn't appear in a collection Editor
and there is only one binding by object !

How To Create a Delagate in a TypeConverter