using System.Collections; namespace FreeTubeSync.Database; public static class MapData { public static void MapFrom(this object obj1, object obj2) { var props = new Dictionary(); var t1Type = obj1.GetType(); var t2Type = obj2.GetType(); var properties = t1Type.GetProperties(); foreach (var property in properties) { props[property.Name] = property.GetValue(obj1); } properties = t2Type.GetProperties(); foreach (var property in properties) { if (props[property.Name] is not IEnumerable) property.SetValue(obj2, props[property.Name]); } } public static void MapTo(this IEnumerable obj1, IList obj2) where T1 : class where T2 : class, new() { foreach (var obj in obj1) { var newObj = new T2(); newObj.MapFrom(obj); obj2.Add(newObj); } } }