private void InitializeKeybinds() { _keyPressHandlers = new Dictionary <ConsoleKey, KeyBind>(); const BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; IEnumerable <KeyBindAttribute> attributes; foreach (var method in this.GetType().GetMethods(flags)) { if (!method.TryGetAttributes(false, out attributes)) { continue; } var handler = (KeyBind)KeyBind.CreateDelegate(typeof(KeyBind), this, method); foreach (var attribute in attributes) { _keyPressHandlers[attribute.Key] = handler; } } }