using System;
using System.Collections.Generic;
using System.Linq;
namespace Ringtoets.Piping.Forms.Helpers
{
///
/// Helper class for generating unique names.
///
/// Has been created due to being obsolete.
public static class NamingHelper
{
///
/// Generate an unique name given a collection of existing named objects.
///
/// Type of objects in the collection.
/// All existing named objects.
/// The base naming scheme to use.
/// Getter method to determine the name of each object in .
/// A unique name based on that is not used
/// in .
public static string GetUniqueName(IEnumerable existingObjects, string nameBase, Func nameGetter)
{
int i = 1;
string result = nameBase;
var existingNames = existingObjects.Select(nameGetter).ToArray();
while (existingNames.Any(name => name.Equals(result)))
{
result = string.Format("{0} ({1})", nameBase, i++);
}
return result;
}
}
}