using System; using System.Collections.Generic; using System.Linq; namespace StableNameDotNet; public static class Extensions { public static bool ContainsAnyInvalidSourceCodeChars(this string s, bool allowCompilerGenerated = false) { foreach (var c in s) switch (c) { case >= 'a' and <= 'z': case >= 'A' and <= 'Z': case >= '0' and <= '9': case '_' or '`': case '.' or '<' or '>' when allowCompilerGenerated: continue; default: return true; } return false; } public static TValue GetOrCreate(this Dictionary dict, TKey key, Func defaultGetter) where TKey : notnull { if (dict.TryGetValue(key, out var value)) return value; value = defaultGetter(); dict.Add(key, value); return value; } public static string Join(this IEnumerable strings, string separator = "") => string.Join(separator, strings); public static ulong StableHash(this string str) => str.Aggregate(0, (current, c) => current * 37 + c); }