InsertUserName
Member
- Joined
- Apr 19, 2020
- Messages
- 7
- Programming Experience
- 1-3
How do you like implementation through generic static class?
How optimised and convenient is this option?
I see the downside of calling Fire, we don’t know exactly what the arguments are, but we can look at delegate. Can we fix this?
How does generic static class ? Does it create an instance for each type?
How optimised and convenient is this option?
I see the downside of calling Fire, we don’t know exactly what the arguments are, but we can look at delegate. Can we fix this?
C#:
public static class Test<T> where T : Delegate
{
private static T _delegate;
public static void Fire(params object[] args) => _delegate?.DynamicInvoke(args);
public static void Subscribe(T action) => _delegate = Delegate.Combine(_delegate, action) as T;
public static void Unsubscribe(T action) => _delegate = Delegate.Remove(_delegate, action) as T;
}
C#:
Test<OnNoteTriggered>.Subscribe(Show);
Test<OnNoteTriggered>.Unsubscribe(Show);
Test<OnNoteTriggered>.Fire("LOOOOOOOOL");
How does generic static class ? Does it create an instance for each type?