/// <summary> /// Setup an option and divine its attributes which will be processed during runtime. /// </summary> /// <param name="lettersDefinition"></param> /// <param name="description"></param> /// <param name="operation"></param> /// <param name="isOptional"></param> /// <param name="ignoreCase"></param> public Option(string lettersDefinition, string description, Action <CommandLineManager> operation, bool isOptional = true, bool ignoreCase = true) { InitialLetterDefinition = lettersDefinition; Letters = Regex.Matches(lettersDefinition, @"[^,\t\s]+") .OfType <Match>() .Select(mt => mt.Value) .ToList(); Letter = Letters.FirstOrDefault(token => token.Length == 1)?.ToUpper(); IsSingleLetterOption = Letter != null; //if (IsSingleLetterOption) // Letter = Letters.FirstOrDefault(token => token.Length == 1)?.ToUpper() ?? Letters[0].Substring(0, 1).ToUpper(); var grouped = Letters.GroupBy(lt => lt.Length == 1) .ToList(); LettersSingle = grouped.Where(gr => gr.Key) .SelectMany(grp => grp.Select(letter => letter [0]) .ToList()) .ToList(); LettersMultiple = grouped.Where(gr => gr.Key == false) .SelectMany(grp => grp) .ToList(); Description = description; Operation = operation; IsOptional = isOptional; }
public void LetterGuessed(string letter) { if (string.IsNullOrEmpty(CurrentPuzzle)) { _guessedLettersQueue.Enqueue(letter); } else { var puzzleLetter = Letters.FirstOrDefault(l => l.Display == letter); if (puzzleLetter != null) { puzzleLetter.IsUsed = true; OnCurrentPuzzleChanged(false); } } }