2024-06-21 23:08:49 +04:00

40 lines
1.2 KiB
C#

using SecuritySystemContracts.StoragesContracts;
namespace SecuritySystemFileImplement.Implements
{
public class BackUpInfoStorage : IBackUpInfoStorage
{
private readonly DataFileSingleton source;
public BackUpInfoStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<T>? GetList<T>() where T : class, new()
{
return (List<T>?)source
.GetType()
.GetProperties()
.FirstOrDefault(
x =>
x.PropertyType.IsGenericType &&
x.PropertyType.GetGenericArguments()[0] == typeof(T))?
.GetValue(source);
}
public Type? GetTypeByModelInterface(string modelInterfaceName)
{
var assembly = typeof(BackUpInfoStorage).Assembly;
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.IsClass &&
type.GetInterface(modelInterfaceName) != null)
{
return type;
}
}
return null;
}
}
}