private IMessageDispatcher CreateMessageDispatcher() { Type messageType = null; var messageSubscriber = MessageSubscriberTypeList.FirstOrDefault(); if (messageSubscriber == null) { if (AnonymousMessageSubscriberList.Count > 0) { var f = AnonymousMessageSubscriberList.First(); messageType = f.GetType(); } } else { messageType = messageSubscriber.BaseType; } if (messageType == null) { return(null); } var baseType = typeof(MessageDispatcher <>); while (true) { var arguments = messageType.GetGenericArguments(); if (arguments.Count() == 1 || messageType == baseType) { messageType = arguments[0]; break; } messageType = messageType.BaseType; } var typeReader = baseType.MakeGenericType(messageType); var result = (IMessageDispatcher)Activator.CreateInstance(typeReader); return(result); }
public void AddSubscriber(object subscriber) { AnonymousMessageSubscriberList.Add(subscriber); }