public static void GenerateNewNameIfNecessary(this IFigure figure, Drawing drawing, List <string> blacklist) { while (figure.Name == null || drawing .Figures //.GetAllFiguresRecursive() // Do not look recursively. .Where(f => f.Name == figure.Name) .Where(f => f != figure) .Any()) { figure.Name = figure.GenerateFigureName(blacklist); } }