logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UniqueNameGenerator

    Single source of truth for "make this name unique among the ones already taken" — the suffix loop that menu option ids, HUD element ids, leaderboard button ids, and audio mixer group names each hand-rolled with a slightly different separator, starting number, and bare-base-name policy. UniqueNameSuffixStyle captures exactly those three differences; comparisons are always ordinal, matching every site this replaces.

    Inheritance
    object
    UniqueNameGenerator
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.Shared.Utils
    Assembly: Serenity.Shared.dll
    Syntax
    public static class UniqueNameGenerator

    Methods

    Next(string, IEnumerable<string>, UniqueNameSuffixStyle)

    Returns the first candidate — the bare baseName when style allows it and it is free, otherwise baseName plus a growing numeric suffix starting at FirstSuffix — that is not present in takenNames. The search is unbounded: with a well-formed takenNames it always terminates, since one more suffix than takenNames has entries cannot already be taken.

    Declaration
    public static string Next(string baseName, IEnumerable<string> takenNames, UniqueNameSuffixStyle style)
    Parameters
    Type Name Description
    string baseName

    The desired name. A null is treated as empty, so an always-suffixed style still produces suffixed names ("_0", "_1", ...) rather than throwing.

    IEnumerable<string> takenNames

    Names already in use. A null is treated as empty.

    UniqueNameSuffixStyle style

    Separator, starting suffix, and bare-base-name policy to apply.

    Returns
    Type Description
    string
    In this article
    © 2026 Serenity. All Rights Reserved