ShortName Class

A utility class to compute unique short names for a given collection of names.

public static class ShortName

Example

// 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

NameDescription
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.cs

Create 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
shortNames IEnumerable<string>
The list of existing short names.
maxLength int
Maximum length of computed short name.
name string
The shorten name.
Returns

string? A string representing the short name; null if the short name cannot be created

Create(IReadOnlyCollection<string>, int)

ShortName.cs

Builds a short names collection.

public static IDictionary<string, string> Create(IReadOnlyCollection<string> names, int maxLength)
Parameters
names IReadOnlyCollection<string>
The input collection of names to shorten. May not be null.
maxLength int
Maximum length of computed short names.
Returns

IDictionary<string, string> A dictionary of shorten names

Create(IReadOnlyCollection<string>, int, IEqualityComparer<string>?)

ShortName.cs

Builds a short names collection.

public static IDictionary<string, string> Create(IReadOnlyCollection<string> names, int maxLength, IEqualityComparer<string>? comparer)
Parameters
names IReadOnlyCollection<string>
The input collection of names to shorten. May not be null.
maxLength int
Maximum length of computed short names.
comparer IEqualityComparer<string>?
Comparer use to compare short names
Returns

IDictionary<string, string> A dictionary of shorten names

Create(ISet<string>, int, string)

ShortName.cs

Create a short name, making sure it does not collide with an existing collection of short names.

public static string? Create(ISet<string> shortNames, int maxLength, string name)
Parameters
shortNames ISet<string>
The set of existing short names.
maxLength int
Maximum length of computed short name.
name string
The name to shorten.
Returns

string? A string representing the short name; null if the short name cannot be created