ShortName Class
A utility class to compute unique short names for a given collection of names.
public static class ShortNameExample
// Create short names for a collection
var names = new[] { "CustomerName", "CustomerNumber", "CustomerAddress" };
var shortNames = ShortName.Create(names, maxLength: 5, StringComparer.OrdinalIgnoreCase);
Assert.Equal("Custo", shortNames["CustomerName"]);
Assert.Equal("Custm", shortNames["CustomerNumber"]);
Assert.Equal("Custe", shortNames["CustomerAddress"]);Methods
| Name | Description |
|---|---|
| Create(IEnumerable<string>, int, string) | Create a short name, making sure it does not collide with an existing collection of short names. |
| Create(IReadOnlyCollection<string>, int) | Builds a short names collection. |
| Create(IReadOnlyCollection<string>, int, IEqualityComparer<string>?) | Builds a short names collection. |
| Create(ISet<string>, int, string) | Create a short name, making sure it does not collide with an existing collection of short names. |
Create overloads
Create(IEnumerable<string>, int, string)
ShortName.csCreate a short name, making sure it does not collide with an existing collection of short names.
public static string? Create(IEnumerable<string> shortNames, int maxLength, string name)Parameters
shortNamesIEnumerable<string>- The list of existing short names.
maxLengthint- Maximum length of computed short name.
namestring- The shorten name.
Returns
string? A string representing the short name; null if the short name cannot be created
Create(IReadOnlyCollection<string>, int)
ShortName.csBuilds a short names collection.
public static IDictionary<string, string> Create(IReadOnlyCollection<string> names, int maxLength)Parameters
namesIReadOnlyCollection<string>- The input collection of names to shorten. May not be null.
maxLengthint- Maximum length of computed short names.
Returns
IDictionary<string, string> A dictionary of shorten names
Create(IReadOnlyCollection<string>, int, IEqualityComparer<string>?)
ShortName.csBuilds a short names collection.
public static IDictionary<string, string> Create(IReadOnlyCollection<string> names, int maxLength, IEqualityComparer<string>? comparer)Parameters
namesIReadOnlyCollection<string>- The input collection of names to shorten. May not be null.
maxLengthint- Maximum length of computed short names.
comparerIEqualityComparer<string>?- Comparer use to compare short names
Returns
IDictionary<string, string> A dictionary of shorten names
Create(ISet<string>, int, string)
ShortName.csCreate a short name, making sure it does not collide with an existing collection of short names.
Parameters
shortNamesISet<string>- The set of existing short names.
maxLengthint- Maximum length of computed short name.
namestring- The name to shorten.
Returns
string? A string representing the short name; null if the short name cannot be created