I am writing a simple event dispatcher where my events come in as objects with a type name clr and a json object representing the original event (after the byte [] was processed in the jobject) that was fired. I use GetEventStore if someone wants to know the specifics.
I want to take this type of clr to do 2 things:
- find classes that implement ihandles and
- calling Consume (type clr) in this class
I managed to get part 1 working perfectly with the following code:
var processedEvent = ProcessRawEvent(@event); var t = Type.GetType(processedEvent.EventClrTypeName); var type = typeof(IHandlesEvent<>).MakeGenericType(t); var allHandlers = container.ResolveAll(type); foreach (var allHandler in allHandlers) { var method = allHandler.GetType().GetMethod("Consume", new[] { t }); method.Invoke(allHandler, new[] { processedEvent.Data }); }
ATM, the problem is that the processed Event.Data is a JObject - I know the type of processed Event.Data, because I have t defined above.
How can I parse this JObject into type t without any unpleasant switching of type name?
iwayneo
source share