namespace DataService; public class DBProcessData(Func KeyConverter, char spilter, string keyName, int skip) where T_PrimaryKey : unmanaged where T_Hierarchy : IDictionary, new() where T_Value : IDictionary, new() { public bool ToDictionary(IEnumerable inputs, out T_Hierarchy? output) { output = default; if (inputs is null) return false; T_Hierarchy cache = []; foreach (dynamic input in inputs) { if (input is null) return false; if (input is not IDictionary inputPair) return false; if (!inputPair.TryGetValue(keyName, out object? primaryKeyValue) || primaryKeyValue is null) return false; if (KeyConverter?.Invoke(primaryKeyValue) is not T_PrimaryKey primaryKey) return false; if (!inputPair.Remove(keyName)) return false; foreach (KeyValuePair rawData in input) ColumAnalizer(cache, rawData.Key.Split(spilter).AsSpan()[skip..], primaryKey, rawData.Value); } output = cache; return true; } private static void ColumAnalizer(/*ref*/ T_Hierarchy cache, Span seprated, T_PrimaryKey key, object value) { if (seprated.Length == 1) { TryGetValueElseCreateNew(cache, seprated[0]).TryAdd(key, value); Console.Write($"{seprated[0]},{value}"); Console.WriteLine(); return; } cache = TryGetValueElseCreateNew(cache, seprated[0]); Console.Write($"{seprated[0]},"); ColumAnalizer(cache, seprated[1..], key, value); } private static T TryGetValueElseCreateNew(T_Hierarchy cache, string key) where T : new() { if (!cache.TryGetValue(key, out object? output) || output is not T dic) { dic = new(); cache[key] = dic; } return dic; } } public class GeneralHeaderAnalizer { public static DateTime? LongToDateTime(object o) { if (o is not long l) return null; return new(l); } } public class GeneralProcessData(int skip = 0) : DBProcessData, DateTime, Dictionary>(GeneralHeaderAnalizer.LongToDateTime, '.', "time", skip) { }