diff --git a/Confectionery/ConfectioneryFileImplement/BackUpInfo.cs b/Confectionery/ConfectioneryFileImplement/BackUpInfo.cs new file mode 100644 index 0000000..cee3913 --- /dev/null +++ b/Confectionery/ConfectioneryFileImplement/BackUpInfo.cs @@ -0,0 +1,44 @@ +using ConfectioneryContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryFileImplement +{ + public class BackUpInfo : IBackUpInfo + { + private readonly DataFileSingleton source; + private readonly PropertyInfo[] sourceProperties; + + public BackUpInfo() + { + source = DataFileSingleton.GetInstance(); + sourceProperties = source.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public); + } + + public List? GetList() where T : class, new() + { + var requredType = typeof(T); + return (List?)sourceProperties.FirstOrDefault(x => x.PropertyType.IsGenericType && x.PropertyType.GetGenericArguments()[0] == requredType) + ?.GetValue(source); + + } + + 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; + } + } +} diff --git a/Confectionery/ConfectioneryFileImplement/ImplementationExtension.cs b/Confectionery/ConfectioneryFileImplement/ImplementationExtension.cs index 095415b..4c1f970 100644 --- a/Confectionery/ConfectioneryFileImplement/ImplementationExtension.cs +++ b/Confectionery/ConfectioneryFileImplement/ImplementationExtension.cs @@ -1,5 +1,6 @@ using ConfectioneryContracts.StoragesContracts; using ConfectioneryDatabaseImplement.Implements; +using ConfectioneryContracts.DI; using System; using System.Collections.Generic; using System.Linq;