using System.Diagnostics.CodeAnalysis; using System.Linq; namespace System { public static class StringExtensions { /// /// Turns a camelCase or PascalCase token into snake_Case. /// /// The input in camelCase or PascalCase. /// /// The input converted to snake_Case. It doesn't alter case so you can call either ToUpper or ToLower without /// any additional penalties. /// /// . public static string ToSnakeCase(this string input) => string.Concat(input.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x : x.ToString())); /// /// Returns if it's not , empty or whitespace. Otherwise returns /// . /// public static string OrIfEmpty(this string text, string alternative) => string.IsNullOrWhiteSpace(text) ? alternative : text; /// /// Returns if the value is or True. /// [SuppressMessage("Minor Code Smell", "S4225:Extension methods should not extend \"object\"", Justification = "No.")] public static bool IsTrueString(this object value) => value?.ToString() == bool.TrueString; } }