public static List <object> Serialize( GameEntity playerEntity, EntityState state, GameSnapshot snapshot, SerializationContext context) { var levelEntity = playerEntity.Position.LevelEntity; if (state == EntityState.Added) { var serializedLevel = LevelSnapshot.Serialize(levelEntity, null, null, context); return(PlayerSnapshot.Serialize(playerEntity, state, null, serializedLevel, context)); } else { if (!snapshot.SerializedLevels.TryGetValue(levelEntity.Id, out var serializedLevel)) { var position = playerEntity.Position; var level = context.DbContext.Entry(position).Property(p => p.LevelId); serializedLevel = LevelSnapshot.Serialize (position.LevelEntity, level.IsModified ? EntityState.Added : state, snapshot.LevelSnapshots.GetValueOrDefault(levelEntity.Id), context); snapshot.SerializedLevels[levelEntity.Id] = serializedLevel; } return(PlayerSnapshot.Serialize( playerEntity, state, snapshot.PlayerSnapshots[playerEntity.Id], serializedLevel, context)); } }
public List <object> Serialize( GameEntity playerEntity, EntityState state, GameSnapshot snapshot, SerializationContext context) => GameSnapshot.Serialize(playerEntity, state, snapshot, context);