feat: parameterless Event type
This commit is contained in:
parent
56321864fb
commit
86c9ed2ba9
@ -3,6 +3,27 @@ using System.Collections.Generic;
|
||||
|
||||
namespace Syntriax.Engine.Core;
|
||||
|
||||
public class Event
|
||||
{
|
||||
private readonly List<EventHandler> listeners = new(8);
|
||||
|
||||
public void AddListener(EventHandler listener) => listeners.Add(listener);
|
||||
public void RemoveListener(EventHandler listener) => listeners.Remove(listener);
|
||||
public void Clear() => listeners.Clear();
|
||||
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 delegate void EventHandler();
|
||||
}
|
||||
|
||||
public class Event<TSender>
|
||||
{
|
||||
private readonly List<EventHandler> listeners = new(8);
|
||||
|
Loading…
x
Reference in New Issue
Block a user