private static Tuple<IActionSpec, string>[] GetOverloadedActionsAndUIds(IActionSpec[] actions) { IActionSpec[] overloadedActions = actions.Where(a => actions.Count(ac => ac.Id == a.Id) > 1).ToArray(); if (overloadedActions.Any()) { return overloadedActions.Select(a => new Tuple<IActionSpec, string>(a, GetUniqueSuffix(a, actions))).ToArray(); } return new Tuple<IActionSpec, string>[] {}; }
private static string GetUniqueSuffix(IActionSpec action, IActionSpec[] actions) { IActionSpec[] 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<IActionSpec, string>(a, ((Func<IActionSpec, string>) (act => act.Parameters.Aggregate("", (acc, p) => a + p.Id + p.Spec.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(Thread.CurrentThread.CurrentCulture); while (actions.Select(a => a.Id).Contains(action.Id + suffix)) { suffix = "0" + suffix; } return suffix; } return ""; }