using aeqw89.DataKeys; namespace Beam.Temporary.Cli { internal static class DataKeyExtensions { public static DataKey WithNamespace(this DataKey dk, string @namespace) { string[] names = @namespace.Split(':'); var agg = (string x, string y) => $"{x}:{y}"; for (int i = 0; i < names.Length; i++) { string test = names.SkipLast(i).Aggregate(agg); if (dk.Identifier.StartsWith(test)) { return new DataKey(dk.Identifier.Replace(test, @namespace)); } } return new DataKey(@namespace + ":" + dk.Identifier); } public static DataKey WithNamespace(this DataKey dk, string @namespace) { return ((DataKey)dk).WithNamespace(@namespace).As(); } public static DataKey WithSuffix(this DataKey dk, string suffix) { return new DataKey(dk.Identifier + suffix); } public static DataKey ToAggregator(this DataKey dk) => dk.WithNamespace("aeqw89:document:aggregators"); public static DataKey ToAuxiliary(this DataKey dk) => dk.WithNamespace("aeqw89:document:auxillaries"); public static DataKey As(this DataKey dk) => new DataKey(dk.Identifier); } }