private void SetKeyHandlerInternal(string[] keys, Action <ConsoleKeyInfo?, object> handler, string briefDescription, string longDescription, ScriptBlock scriptBlock) { foreach (var key in keys) { var chord = ConsoleKeyChordConverter.Convert(key); if (chord.Length == 1) { _dispatchTable[chord[0]] = MakeKeyHandler(handler, briefDescription, longDescription, scriptBlock); } else { _dispatchTable[chord[0]] = MakeKeyHandler(Chord, "ChordFirstKey"); Dictionary <ConsoleKeyInfo, KeyHandler> secondDispatchTable; if (!_chordDispatchTable.TryGetValue(chord[0], out secondDispatchTable)) { secondDispatchTable = new Dictionary <ConsoleKeyInfo, KeyHandler>(); _chordDispatchTable[chord[0]] = secondDispatchTable; } secondDispatchTable[chord[1]] = MakeKeyHandler(handler, briefDescription, longDescription, scriptBlock); } } }
private void RemoveKeyHandlerInternal(string[] keys) { foreach (var key in keys) { var chord = ConsoleKeyChordConverter.Convert(key); if (chord.Length == 1) { _dispatchTable.Remove(chord[0]); } else { Dictionary <ConsoleKeyInfo, KeyHandler> secondDispatchTable; if (_chordDispatchTable.TryGetValue(chord[0], out secondDispatchTable)) { secondDispatchTable.Remove(chord[1]); if (secondDispatchTable.Count == 0) { _dispatchTable.Remove(chord[0]); } } } } }