logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class SerenityTextEliding

    Pure string shaping for display labels too long or too tall for their control: elide from the left (generated names keep their distinguishing tail), elide from the right (prose keeps its start), or collapse to one line.

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

    Methods

    CollapseToSingleLine(string)

    Turns every run of whitespace, line breaks included, into one space and trims both ends, so multi-line text fits a single-line label. A null text is treated as empty.

    Declaration
    public static string CollapseToSingleLine(string text)
    Parameters
    Type Name Description
    string text

    The text to put on one line.

    Returns
    Type Description
    string

    ElideFromLeft(string, int)

    Returns text unchanged when it already fits within maxLength. Otherwise keeps the tail and prefixes an ellipsis so the result never exceeds maxLength characters — the distinguishing part of Serenity's generated names (a specific profile, module, or variant) usually lives at the end rather than the start, so keeping the prefix instead would throw away the information the reader actually needs. A surrogate pair is never split. A null text is treated as empty, and a non-positive maxLength always yields an empty string.

    Declaration
    public static string ElideFromLeft(string text, int maxLength)
    Parameters
    Type Name Description
    string text

    The candidate label to elide.

    int maxLength

    The maximum length of the returned string, including the ellipsis.

    Returns
    Type Description
    string

    ElideFromRight(string, int)

    Returns text unchanged when it already fits within maxLength. Otherwise keeps the head and suffixes an ellipsis so the result never exceeds maxLength characters — prose keeps its start. A surrogate pair is never split. A null text is treated as empty, and a non-positive maxLength always yields an empty string.

    Declaration
    public static string ElideFromRight(string text, int maxLength)
    Parameters
    Type Name Description
    string text

    The candidate label to elide.

    int maxLength

    The maximum length of the returned string, including the ellipsis.

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