using AutomobilePlantContracts.StoragesContracts; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace AutomomilePlantFileImplement.Implements { public class BackUpInfo : IBackUpInfo { public List? GetList() where T : class, new() { var context = DataFileSingleton.GetInstance(); Type myType = typeof(DataFileSingleton); string property = $"{typeof(T).FullName}"; string nameList = ""; foreach (PropertyInfo prop in myType.GetProperties( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)) { var list = prop.GetValue(context); var typeList = list.GetType().GetGenericArguments().Single(); if (property.Equals($"{typeList.FullName}")) { nameList = prop.Name; break; } } var propertyInfo = myType.GetProperty(nameList); var values = (List)propertyInfo.GetValue(context); return values; } public Type? GetTypeByModelInterface(string modelInterfaceName) { var assembly = typeof(BackUpInfo).Assembly; var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsClass && type.GetInterface(modelInterfaceName) != null) { return type; } } return null; } } }