Table of Contents

Class StringExtensions

Namespace
Trellis
Assembly
Trellis.Primitives.dll

String manipulation helpers for value object field name normalization.

public static class StringExtensions
Inheritance
StringExtensions
Inherited Members

Methods

NormalizeFieldName(string?, string)

Normalizes an optional field name to camelCase, falling back to a default name.

public static string NormalizeFieldName(this string? fieldName, string defaultName)

Parameters

fieldName string

The optional field name to normalize.

defaultName string

The default field name if fieldName is null or empty.

Returns

string

The camelCased field name, or defaultName if not provided.

ParseScalarValue<T>(string?)

Parses a string value using the specified IScalarValue<TSelf, TPrimitive> factory. Throws FormatException if the value is invalid.

public static T ParseScalarValue<T>(string? s) where T : class, IScalarValue<T, string>

Parameters

s string

Returns

T

Type Parameters

T

ToCamelCase(string?)

Converts the first character of a string to lowercase while preserving the rest of the string. Used primarily for converting C# PascalCase property names to camelCase for JSON serialization and validation error field names.

public static string ToCamelCase(this string? str)

Parameters

str string

The string to convert to camelCase.

Returns

string

A new string with the first character in lowercase and the remaining characters unchanged. If the string is null or empty, returns Empty.

Remarks

This method is used internally to ensure consistent field naming in validation errors and JSON responses. For example, converting "Email" to "email" or "FirstName" to "firstName".

Examples:

  • "Email" → "email"
  • "FirstName" → "firstName"
  • "A" → "a"
  • "" → ""
  • <c>(string)null</c> → ""

TryParseScalarValue<T>(string?, out T)

Tries to parse a string value using the specified IScalarValue<TSelf, TPrimitive> factory.

public static bool TryParseScalarValue<T>(string? s, out T result) where T : class, IScalarValue<T, string>

Parameters

s string
result T

Returns

bool

Type Parameters

T