public static MyReadOnlyObservableCollection<InputBinding> GetDefaultInputBindings() { if (defaultInputBindings == null) { defaultInputBindings = new MyReadOnlyObservableCollection<InputBinding>(new ObservableCollection<InputBinding>(getDefaultInputBindings())); CheckThatTheDefaultInputBindingCollectionContainsAllCommandsThanNeedToBeBound(defaultInputBindings); } return defaultInputBindings; }
private static void CheckThatTheDefaultInputBindingCollectionContainsAllCommandsThanNeedToBeBound(MyReadOnlyObservableCollection<InputBinding> inputBindings) { //gets all commands that are assigned var assignedCommands = inputBindings.Select(binding => binding.Command).ToList(); //the following commands don't have to be assigned: var definitelyUnassigned = new ICommand[] { Commands.InsertCharacter, //treated specially: It's associated directly to //Commands.PlaceCaret, //Commands.ExtendAndPlaceCaret, Commands.MoveCaretRightOut, //No such caret movement exist in Word's Equation Editor, but Commands.MoveCaretLeftOut };//they are useful as template to be copied and modified //gets the first command that isn't assigned but should be var unassignedCommand = assignedCommands.Where(command => !command.IsAnyOf(definitelyUnassigned))//definitelyUnassigned has the commands that don't need to be assigned .FirstOrDefault(not<ICommand>(assignedCommands.Contains)); //get the first that isn't assigned in the result Contract.Assert(unassignedCommand == null, string.Format("Forgot to assign {0}", unassignedCommand)); }