private static Tuple<INakedObjectAction, string>[] GetOverloadedActionsAndUIds(INakedObjectAction[] actions) { INakedObjectAction[] overloadedActions = actions.Where(a => actions.Count(ac => ac.Id == a.Id) > 1).ToArray(); if (overloadedActions.Any()) { return overloadedActions.Select(a => new Tuple<INakedObjectAction, string>(a, GetUniqueSuffix(a, actions))).ToArray(); } return new Tuple<INakedObjectAction, string>[] { }; }
private static string GetUniqueSuffix(INakedObjectAction action, INakedObjectAction[] actions) { INakedObjectAction[] overloadedActions = actions.Where(a => a.Id == action.Id && actions.Count(ac => ac.Id == a.Id) > 1).ToArray(); if (overloadedActions.Any()) { var actionAndParms = overloadedActions.Select(a => new Tuple<INakedObjectAction, string>(a, ((Func<INakedObjectAction, string>)(act => act.Parameters.Aggregate("", (acc, p) => a + p.Id + p.Specification.FullName)))(a))); int index = 0; var orderedActions = actionAndParms.OrderBy(ap => ap.Item2).Select(ap => ap.Item1).ToDictionary(a => a, a => index++); var suffix = orderedActions[action].ToString(); while (actions.Select(a => a.Id).Contains(action.Id + suffix)) { suffix = "0" + suffix; } return suffix; } return ""; }