Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class CustomEvent
- {
- private readonly List<Action> events;
- public CustomEvent(int capacity = 1)
- {
- events = new List<Action>(capacity);
- }
- public event Action Event
- {
- add { events.Add(value); }
- remove { events.Remove(value); }
- }
- public void Execute()
- {
- for (var i = 0; i < events.Count; ++i)
- {
- if (events[i] != null)
- {
- events[i]();
- }
- }
- }
- }
- public class CustomEvent<T>
- {
- private readonly List<Action<T>> events;
- public CustomEvent(int capacity = 1)
- {
- events = new List<Action<T>>(capacity);
- }
- public event Action<T> Event
- {
- add { events.Add(value); }
- remove { events.Remove(value); }
- }
- public void Execute(T value)
- {
- for (var i = 0; i < events.Count; ++i)
- {
- if (events[i] != null)
- {
- events[i](value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement