private void FixEntityNames(IMapObject obj, List <string> names, bool makeEntitesUnique, bool prefixEntityNames, string entityNamePrefix) { 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 if (!entity.EntityData.Properties.ContainsKey("targetname")) { continue; } var prop = entity.EntityData.Properties["targetname"]; // Skip unnamed entities if (String.IsNullOrWhiteSpace(prop)) { continue; } // Add the prefix before the unique check if (prefixEntityNames) { prop = entityNamePrefix + prop; } // Make the name unique if (makeEntitesUnique) { var name = prop; // 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 entity.EntityData.Properties["targetname"] = newName; names.Add(newName); } } }
/// <summary> /// Flattens the tree underneath this node. /// </summary> /// <returns>A list containing all the descendants of this node (including this node)</returns> public static List <IMapObject> FindAll(this IMapObject obj) { return(obj.Find(x => true)); }