/// <summary> /// Register an interpretor /// </summary> /// <param name="interpretor">Interpretor to register with <see cref="IInterpretor"/> key and instance for value</param> public static void Register(IInterpretor interpretor) { var type = interpretor.GetType(); var interfaces = type.GetInterfaces(); List <Type> matchingInterfaces = new List <Type>(); Type interpretorInterface = typeof(IInterpretor); foreach (var @interface in interfaces) { if (@interface != interpretorInterface && interpretorInterface.IsAssignableFrom(@interface) && @interface.Namespace == interpretorInterface.Namespace) { matchingInterfaces.Add(@interface); } } foreach (var matchingInterface in matchingInterfaces) { if (Interpretors.ContainsKey(matchingInterface)) { throw new InvalidOperationException($"Type {type.FullName} already registred in interpretors"); } Interpretors[matchingInterface] = interpretor; } }
/// <summary> /// Register an interpretor for a specific <paramref name="type"/> if not already exists /// </summary> /// <param name="type">Key type for registering</param> /// <param name="interpretor">Interpretor to register with <paramref name="type"/> key and instance for value</param> public static void RegisterForTypeIfNotExists(Type type, IInterpretor interpretor) { if (Interpretors.ContainsKey(type)) { return; } Interpretors[type] = interpretor; }
/// <summary> /// Register an interpretor for a specific <paramref name="type"/> /// </summary> /// <param name="type">Key type for registering</param> /// <param name="interpretor">Interpretor to register with <paramref name="type"/> key and instance for value</param> public static void RegisterForType(Type type, IInterpretor interpretor) { if (Interpretors.ContainsKey(type)) { throw new InvalidOperationException($"Type {type.FullName} already registred in interpretors"); } Interpretors[type] = interpretor; }
private static void InterpretorOnKeyPressed(IInterpretor sender, IKeyPressArgs args) { if (!(sender is Interpretor interpretor)) { return; } InterpretorOnCursorMove(interpretor, new CursorInformation(null, interpretor.CursorPosition, args.Key)); }
// note: SocketManager.AddListener erstellt eine kopie das _listeners array // darum gibt es jetzt eine neue funktion SocketManager.UpdateListener public ApplicationHost(string fileName, SocketManager sm) { if (fileName == null) throw new ArgumentNullException("fileName"); if (sm == null) throw new ArgumentNullException("sm"); this._fileName = fileName; this._socketManager = sm; this._socketManager.AddListener(this); this._interpretor = new ApplicationHostInterpretor(); }
private static bool InterpretorOnCursorMove(IInterpretor sender, ICursorInformation args) { var orgPosition = (Console.CursorLeft, Console.CursorTop); if (args.OldCursorPosition.HasValue && args.OldCursorPosition.Value >= 0) { Console.SetCursorPosition(0, args.OldCursorPosition.Value); WriteMenuItem(' ' + sender.GetMenu().ElementAt(args.OldCursorPosition.Value)?.TrimStart(), sender as Interpretor); } if (args.NewCursorPosition.HasValue && args.NewCursorPosition.Value >= 0) { Console.SetCursorPosition(0, args.NewCursorPosition.Value); WriteMenuItem('>' + sender.GetMenu().ElementAt(args.NewCursorPosition.Value)?.TrimStart(), sender as Interpretor); } Console.SetCursorPosition(orgPosition.CursorLeft, orgPosition.CursorTop); return(false); //handled }
/// <summary> /// /// </summary> /// <param name="next"></param> public BaseInterpretor(IInterpretor next) { this._next = next; }