private LevelDescriptionGrid2D <RoomWrapper> GetWrappedLevelDescription(LevelDescriptionGrid2D <RoomBase> originalLevelDescription) { var levelDescription = new LevelDescriptionGrid2D <RoomWrapper>(); var srcProperties = originalLevelDescription.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); var dstProperties = levelDescription.GetType().GetProperties( BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); foreach (var srcProperty in srcProperties) { var dstProperty = dstProperties.First(x => x.Name == srcProperty.Name); if (dstProperty.CanWrite) { dstProperty.SetValue(levelDescription, srcProperty.GetValue(originalLevelDescription)); } } var id = 0; var mapping = originalLevelDescription .GetGraphWithoutCorridors() .Vertices .Select(x => (x, new RoomWrapper(id++, x.GetDisplayName()))) .ToDictionary(x => x.x, x => x.Item2); foreach (var pair in mapping) { levelDescription.AddRoom(pair.Value, originalLevelDescription.GetRoomDescription(pair.Key)); } foreach (var edge in originalLevelDescription.GetGraphWithoutCorridors().Edges) { var from = mapping[edge.From]; var to = mapping[edge.To]; levelDescription.AddConnection(from, to); } return(levelDescription); }