private void InvokeEventHandler(object instance, MethodInfo method)
{
ParameterInfo[] args = method.GetParameters();
switch (args.Length)
{
case 2:
method.Invoke(instance, new object[] { this, new EventArgs() });
break;
case 1:
method.Invoke(instance, new object[] { this });
break;
case 0:
method.Invoke(instance, null);
break;
default:
throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "The specified method was expected to have 0, 1, or 2 parameters: {0}", method.ToString()));
}
}