protected void InitContextMenu() { if (contextData == null) { contextData = new Dictionary <string, ContextMenuData>(); } else { contextData.Clear(); } // Get context menu var targetType = target.GetType(); var methods = GetAllMethods(targetType).ToArray(); for (var index = 0; index < methods.GetLength(0); ++index) { var methodInfo = methods[index]; var contextMenuAttributes = methodInfo.GetCustomAttributes(ContextMenuType, false); var contextMenuLayoutAttributes = methodInfo.GetCustomAttributes(ContextMenuLayoutType, false); for (var i = 0; i < contextMenuAttributes.Length; i++) { var contextMenu = (ContextMenu)contextMenuAttributes[i]; if (contextMenu == null) { continue; } ContextMenuLayoutAttribute layout = null; for (var innerIndex = 0; innerIndex < contextMenuLayoutAttributes.Length; innerIndex++) { var contextMenuLayoutAttribute = (ContextMenuLayoutAttribute)contextMenuLayoutAttributes[innerIndex]; if (contextMenuLayoutAttribute == null) { continue; } layout = contextMenuLayoutAttribute; break; } if (contextData.ContainsKey(contextMenu.menuItem)) { var data = contextData[contextMenu.menuItem]; if (contextMenu.validate) { data.Validate = methodInfo; } else { data.Function = methodInfo; } if (layout != null) { data.Layout = new ContextMenuData.LayoutOptions(layout); } contextData[data.MenuItem] = data; } else { var data = new ContextMenuData(contextMenu.menuItem); if (contextMenu.validate) { data.Validate = methodInfo; } else { data.Function = methodInfo; } if (layout != null) { data.Layout = new ContextMenuData.LayoutOptions(layout); } contextData.Add(data.MenuItem, data); } } } }
public LayoutOptions(ContextMenuLayoutAttribute layout) { Row = layout.Row; Column = layout.Column; AmountPerLine = layout.AmountPerLine; }