/// <summary> /// Constructor that gets the finder of methods marked with specific atrributes. /// </summary> /// <param name="finder"></param> public EventBus(IHandlerFindingStrategy finder) { //TODO : readerwriterlockslim , conccurentdictionary. //Replace with ninject tools. this.finder = finder; handlersByType = HashMultiMap <Type, EventHandler> .Create(); handlersByTypeLock = new ReaderWriterLockSlim(); eventsToDispatch = new ThreadLocal <Queue <EventWithHandler> >(() => { return(new Queue <EventWithHandler>()); }); isDispatching = new ThreadLocal <Boolean>(() => { return(false); }); }
/// <summary> /// This getting an object and extract all the methods marked with Subscribe attribute. /// </summary> /// <param name="subscriber">The object whose methods are desired to be event handlers</param> /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns> public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber) { IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create(); foreach (MethodInfo method in GetMarkedMethods(subscriber)) { ParameterInfo[] parmetersTypes = method.GetParameters(); Type eventType = parmetersTypes[0].ParameterType; EventHandler handler = new EventHandler(subscriber, method); methodsInSubscriber.Add(eventType, handler); } return(methodsInSubscriber); }
public override bool Equals(object obj) { Boolean answer = false; if (obj is HashMultiMap <K, V> ) { HashMultiMap <K, V> other = (HashMultiMap <K, V>)obj; answer = true; foreach (K key in this.Keys) { } } return(answer); }
/// <summary> /// This getting an object and extract all the methods marked with Subscribe attribute. /// </summary> /// <param name="subscriber">The object whose methods are desired to be event handlers</param> /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns> public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber) { IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create(); foreach (MethodInfo method in GetMarkedMethods(subscriber)) { Subscribe attr = (Subscribe)method.GetCustomAttribute(typeof(Subscribe)); int priority = attr.GetPriority(); ParameterInfo[] parmetersTypes = method.GetParameters(); Type eventType = parmetersTypes[0].ParameterType; EventHandler handler = new EventHandler(subscriber, method, priority); methodsInSubscriber.Add(eventType, handler); } return(methodsInSubscriber); }