private void AddEventHandlerMenuItems( string targetName, string eventName, Type handlerType, int indent, LookupListItem item) { BindingFlags bindingAttr = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance; MethodInfo[] mia = handlerType.GetMethods(bindingAttr); foreach (MethodInfo mi in mia) { if (mi.Name != "Invoke") { continue; } string paddingFull = new String(' ', indent); string paddingShort = new String(' ', (indent > 4 ? indent - 4 : indent)); string methodParameters = CSharpFormattingTools.GetMethodParameters( mi.GetParameters()); string methodParameterNames = CSharpFormattingTools.GetMethodParameterNames( mi.GetParameters()); /* * Full event handler. */ LookupMenuItem lmi1 = new LookupMenuItem(); string displayText1 = Resources.InsertEventHandler; string insertText1 = String.Format( @"{0} += new {1}({2}_{0}); {4}private void {2}_{0}{3} {4}{{ {4}}} ", eventName, handlerType.Name, FormatEventHandlerName(targetName), methodParameters, paddingShort); lmi1.DisplayText = displayText1; lmi1.InsertText = insertText1; item.MenuItems.Add(lmi1); /* * Anonymous event handler. */ LookupMenuItem lmi2 = new LookupMenuItem(); string displayText2 = Resources.InsertAnonEventHandler; string insertText2 = String.Format( @"{0} += delegate {1} {2}{{ {2}}};", eventName, methodParameters, paddingFull); lmi2.DisplayText = displayText2; lmi2.InsertText = insertText2; item.MenuItems.Add(lmi2); /* * Lambda event handler. */ LookupMenuItem lmi3 = new LookupMenuItem(); string displayText3 = Resources.InsertLambdaEventHandler; string insertText3 = String.Format( @"{0} += {1} => {2}{{ {2}}};", eventName, methodParameterNames, paddingFull); lmi3.DisplayText = displayText3; lmi3.InsertText = insertText3; item.MenuItems.Add(lmi3); } }