using System; using System.Collections.Generic; namespace Syntriax.Engine.Core; public class Event { private readonly List listeners = new(1000); public void AddListener(Action listener) => listeners.Add(listener); public void RemoveListener(Action listener) => listeners.Remove(listener); public void Invoke() { for (int i = 0; i < listeners.Count; i++) try { listeners[i].Invoke(); } catch (Exception exception) { string methodCallRepresentation = $"{listeners[i].Method.DeclaringType?.FullName}.{listeners[i].Method.Name}()"; Console.WriteLine($"Unexpected exception on invocation of method {methodCallRepresentation}:{Environment.NewLine}{exception.InnerException}"); } } } public class Event { private readonly List> listeners = new(1000); public void AddListener(Action listener) => listeners.Add(listener); public void RemoveListener(Action listener) => listeners.Remove(listener); public void Invoke(T1 argument) { for (int i = 0; i < listeners.Count; i++) try { listeners[i].Invoke(argument); } catch (Exception exception) { string methodCallRepresentation = $"{listeners[i].Method.DeclaringType?.FullName}.{listeners[i].Method.Name}({argument})"; Console.WriteLine($"Unexpected exception on invocation of method {methodCallRepresentation}:{Environment.NewLine}{exception.InnerException}"); } } } public class Event { private readonly List> listeners = new(1000); public void AddListener(Action listener) => listeners.Add(listener); public void RemoveListener(Action listener) => listeners.Remove(listener); public void Invoke(T1 argument1, T2 argument2) { for (int i = 0; i < listeners.Count; i++) try { listeners[i].Invoke(argument1, argument2); } catch (Exception exception) { string methodCallRepresentation = $"{listeners[i].Method.DeclaringType?.FullName}.{listeners[i].Method.Name}({string.Join(", ", argument1, argument2)})"; Console.WriteLine($"Unexpected exception on invocation of method {methodCallRepresentation}:{Environment.NewLine}{exception.InnerException}"); } } } public class Event { private readonly List> listeners = new(1000); public void AddListener(Action listener) => listeners.Add(listener); public void RemoveListener(Action listener) => listeners.Remove(listener); public void Invoke(T1 argument1, T2 argument2, T3 argument3) { for (int i = 0; i < listeners.Count; i++) try { listeners[i].Invoke(argument1, argument2, argument3); } catch (Exception exception) { string methodCallRepresentation = $"{listeners[i].Method.DeclaringType?.FullName}.{listeners[i].Method.Name}({string.Join(", ", argument1, argument2, argument3)})"; Console.WriteLine($"Unexpected exception on invocation of method {methodCallRepresentation}:{Environment.NewLine}{exception.InnerException}"); } } } public class Event { private readonly List> listeners = new(1000); public void AddListener(Action listener) => listeners.Add(listener); public void RemoveListener(Action listener) => listeners.Remove(listener); public void Invoke(T1 argument1, T2 argument2, T3 argument3, T4 argument4) { for (int i = 0; i < listeners.Count; i++) try { listeners[i].Invoke(argument1, argument2, argument3, argument4); } catch (Exception exception) { string methodCallRepresentation = $"{listeners[i].Method.DeclaringType?.FullName}.{listeners[i].Method.Name}({string.Join(", ", argument1, argument2, argument3, argument4)})"; Console.WriteLine($"Unexpected exception on invocation of method {methodCallRepresentation}:{Environment.NewLine}{exception.InnerException}"); } } }