using System.Collections.Generic;
public static void Main()
List<AccountEvent> events = new List<AccountEvent>
var denormalizer = new CustomerAccountDenormalizer();
var state = denormalizer.ReplayState(events);
CustomerID: {state.CustomerId}
AccountID: {state.AccountId}
Balance: {state.Balance:C}
public class CustomerAccountDenormalizer
public Account ReplayState(IEnumerable<AccountEvent> events)
var account = new Account();
Handle((dynamic) e, account);
private void Handle(AccountCreated e, Account state)
state.CustomerId = e.CustomerId;
state.AccountId = e.AccountId;
private void Handle(CustomerDeposit e, Account state)
state.Balance += e.Amount;
private void Handle(CustomerWithdrawal e, Account state)
state.Balance -= e.Amount;
public string CustomerId { get; set; }
public string AccountId { get; set; }
public decimal Balance { get; set; }
public class AccountEvent
public string Type { get; set; }
public class AccountCreated : AccountEvent
public string AccountId { get; set; }
public string CustomerId { get; set; }
public class CustomerDeposit : AccountEvent
public string CustomerId { get; set; }
public string AccountId { get; set; }
public decimal Amount { get; set; }
public class CustomerWithdrawal : AccountEvent
public string CustomerId { get; set; }
public string AccountId { get; set; }
public decimal Amount { get; set; }