I have a dictionary - the key of which is System.Type
. I do not constrain the dictionary entries further; however, the dictionary is only exposed through a public class interface. I am mimicking an event system.
The System.Collections.Generic
Dictionary
looks like:
private Dictionary<Type, HashSet<Func<T>>> _eventResponseMap;
One of the methods that exposes the dictionary has the following signature:
public bool RegisterEventResponse<T>(Type eventType, Func<T> function)
However, I don't want the class user to be able to add any System.Type
to the dictionary through this signature. Is there a way I can further constrain the Type
parameter?
What I really want is something akin to (pseudo-code):
public bool RegisterEventResponse<T>(Type eventType, Func<T> function) where Type : ICustomEventType