logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class NamingSanitizer

    Single source of truth for the file-name and C#-identifier sanitization rules the editor asset creators (GameSettingCreator, FeedbackCreator, CutsceneCreator, ModalCreator, ThemeCreator, AudioChannelCreator, and the audio/music batch importers) each duplicated near-identically. Engine-agnostic (pure string logic over GetInvalidFileNameChars()), so it lives in Shared rather than any one Business or Unity module.

    Inheritance
    object
    NamingSanitizer
    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 NamingSanitizer

    Methods

    AppendSuffixUnlessPresent(string, string)

    Appends suffix to name unless name already ends with it (case-insensitive) — the guard a composed name needs whenever the user-typed base could itself already carry the suffix, e.g. Theme Builder's "...Theme" (a name of "Builder Test Theme" must not become "Builder Test ThemeTheme") and Service Extension Creator's "...Service".

    Declaration
    public static string AppendSuffixUnlessPresent(string name, string suffix)
    Parameters
    Type Name Description
    string name

    The base name. Trimmed; null is treated as empty.

    string suffix

    The suffix to ensure exactly once at the end. A null or empty suffix leaves name unchanged.

    Returns
    Type Description
    string

    FileNameSafe(string, string)

    Strips characters that are illegal in file names (replacing each with '_'), so the result is always a valid asset file name. Trims whitespace first; a null name is treated as empty. Returns fallback when the sanitized result would be empty.

    Declaration
    public static string FileNameSafe(string name, string fallback)
    Parameters
    Type Name Description
    string name

    The candidate name to sanitize.

    string fallback

    Value returned when sanitizing name yields an empty string.

    Returns
    Type Description
    string

    ToPascalIdentifier(string, string)

    Converts an arbitrary name into a valid PascalCase C# identifier (alphanumeric, letter-led; non-alphanumeric runs become a capitalization boundary). Returns fallback (default: empty string) when value is null/blank or yields no identifier characters.

    Declaration
    public static string ToPascalIdentifier(string value, string fallback = "")
    Parameters
    Type Name Description
    string value

    The candidate name to convert.

    string fallback

    Value returned when value is null/blank. Defaults to Empty.

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