private void FixEntityNames(MapObject obj, List<string> names) { if (!_makeEntitesUnique && !_prefixEntityNames) return; var ents = obj.Find(x => x is Entity) .OfType<Entity>() .Where(x => x.EntityData != null); foreach (var entity in ents) { // Find the targetname property var prop = entity.EntityData.Properties.FirstOrDefault(x => x.Key == "targetname"); if (prop == null) continue; // Skip unnamed entities if (String.IsNullOrWhiteSpace(prop.Value)) continue; // Add the prefix before the unique check if (_prefixEntityNames) { prop.Value = _entityNamePrefix + prop.Value; } // Make the name unique if (_makeEntitesUnique) { var name = prop.Value; // Find a unique new name for the entity var newName = name; var counter = 1; while (names.Contains(newName)) { newName = name + "_" + counter; counter++; } // Set the new name and add it into the list prop.Value = newName; names.Add(newName); } } }