Beispiel #1
0
    public static T?SelectInteractive <T>(string str, Dictionary <string, T> dictionary, string context) where T : class
    {
        T?result = dictionary.TryGetC(str);

        if (result != null)
        {
            return(result);
        }

        StringDistance sd = new StringDistance();

        var list = dictionary.Keys.Select(s => new { s, lcs = sd.LongestCommonSubsequence(str, s) }).OrderByDescending(s => s.lcs !).Select(a => a.s !).ToList();

        var cs = new ConsoleSwitch <int, string>("{0} has been renamed in {1}".FormatWith(str, context));

        cs.Load(list);

        string?selected = cs.Choose();

        if (selected == null)
        {
            return(null);
        }

        return(dictionary.GetOrThrow(selected));
    }
Beispiel #2
0
    public static T[]? ChooseConsoleMultiple <T>(this IEnumerable <T> collection, Func <T, string>?getString = null, string?message = null) where T : class
    {
        var cs = new ConsoleSwitch <int, T>(message ?? ConsoleMessage.SelectOneOfTheFollowingOptions.NiceToString());

        cs.Load(collection.ToList(), getString);
        return(cs.ChooseMultiple());
    }