/// <summary> /// Adds a converter for the specified event to be used when upgrading events. /// </summary> /// <remarks> /// <para>This uses the type resolver to look up the name of the event.</para> /// <para>You do not need to add a converter for every event, only those that require upgrading. /// If an event has no converter added it will be left un-modified.</para> /// </remarks> /// <param name="eventType">The event type the <paramref name="converter"/> handles.</param> /// <param name="converter">The converter for the event specified by <paramref name="eventType"/>.</param> /// <exception cref="ArgumentNullException">If <paramref name="eventType"/> or <paramref name="converter"/> is <value>null</value>.</exception> /// <exception cref="ArgumentException">If a converter for <paramref name="eventType"/> has already been added.</exception> public void AddConverter(Type eventType, IEventConverter converter) { Contract.Requires <ArgumentNullException>(eventType != null, "eventType"); Contract.Requires <ArgumentNullException>(converter != null, "converter"); string name = _typeResolver.EventNameFor(eventType); AddConverter(name, converter); }
public StoredEvent <JObject> Serialize(ISourcedEvent theEvent) { var eventName = _typeResolver.EventNameFor(theEvent.GetType()); var data = JObject.FromObject(theEvent, _serializer); StoredEvent <JObject> obj = new StoredEvent <JObject>( theEvent.EventIdentifier, theEvent.EventTimeStamp, eventName, theEvent.EventVersion, theEvent.EventSourceId, theEvent.EventSequence, data); data.Remove("EventIdentifier"); data.Remove("EventTimeStamp"); data.Remove("EventName"); data.Remove("EventVersion"); data.Remove("EventSourceId"); data.Remove("EventSequence"); return(obj); }
public JObject Serialize(object theEvent, out string eventName) { eventName = _typeResolver.EventNameFor(theEvent.GetType()); return(JObject.FromObject(theEvent, _serializer)); }