/// <summary> /// Maps the persisted entity back to the <see cref="IEntityEvent" />. /// </summary> /// <param name="eventEntity"> /// The stored event entity to be mapped. /// </param> /// <returns> /// The <see cref="IEntityEvent" />. /// </returns> protected virtual IEntityEvent MapEvent(TEventEntity eventEntity) { Check.NotNull(eventEntity, nameof(eventEntity)); IEntityEvent?entityEvent; if (eventEntity.ClrType != null) { var eventType = TypesCache.GetType(eventEntity.ClrType); entityEvent = (IEntityEvent?)JsonSerializer.Deserialize( eventEntity.SerializedEvent, eventType); } else { entityEvent = (IEntityEvent?)PolymorphicJsonSerializer.Deserialize(eventEntity.SerializedEvent); } if (entityEvent == null) { throw new InvalidOperationException("Failed to deserialize the persisted event."); } entityEvent.Sequence = eventEntity.Sequence; entityEvent.Timestamp = eventEntity.Timestamp; return(entityEvent); }
/// <summary> /// Maps the persisted entity back to the <see cref="IEntityEvent" />. /// </summary> /// <param name="eventEntity"> /// The stored event entity to be mapped. /// </param> /// <returns> /// The <see cref="IEntityEvent" />. /// </returns> protected virtual IEntityEvent MapEvent(TEventEntity eventEntity) { Check.NotNull(eventEntity, nameof(eventEntity)); IEntityEvent entityEvent; if (eventEntity.ClrType != null) { var eventType = TypesCache.GetType(eventEntity.ClrType); entityEvent = (IEntityEvent)JsonSerializer.Deserialize(eventEntity.SerializedEvent, eventType); } else { entityEvent = (IEntityEvent)PolymorphicJsonSerializer.Deserialize(eventEntity.SerializedEvent); } entityEvent.Sequence = eventEntity.Sequence; entityEvent.Timestamp = eventEntity.Timestamp; return(entityEvent); }