Exemplo n.º 1
0
        private List<KeyValuePair<string, string>> FormatSuggestionList(
            MatchResult savedMatch,
            IEnumerable<MatchResult> suggestions,
            bool addBlank)
        {
            IEnumerable<MatchResult> list;
            if (savedMatch != null)
            {
                // Add the saved match to the top of the suggestions list
                list = ConcatWithDistinct(
                    savedMatch,
                    suggestions).ToList();
            }
            else
            {
                list = suggestions;
            }

            // format the list
            List<KeyValuePair<string, string>> formattedList =
                list.Select(
                    x =>
                        new KeyValuePair<string, string>
                            (
                            x.Location,
                            string.Format("{0}:   {1:P2}", x.Location, x.Coefficient)
                            )).ToList();

            if (addBlank)
            {
                // add a leave blank option to the bottom of the list
                formattedList.Add(new KeyValuePair<string, string>(null, LeaveBlankText));
            }
            return formattedList;
        }
Exemplo n.º 2
0
 private IEnumerable<MatchResult> ConcatWithDistinct(
     MatchResult matchResult,
     IEnumerable<MatchResult> b)
 {
     List<MatchResult> a = new List<MatchResult>();
     a.Add(matchResult);
     var set = new HashSet<string>(a.Select(x => x.Location.ToLower()));
     var list = a.ToList();
     foreach (var match in b)
     {
         if (!set.Contains(match.Location.ToLower()))
         {
             list.Add(match);
         }
     }
     return list;
 }