43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
|
using FlowerShopContracts.StoragesContracts;
|
|||
|
using System.Reflection;
|
|||
|
|
|||
|
namespace FlowerShopFileImplement.Implements
|
|||
|
{
|
|||
|
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<T>? GetList<T>() where T : class, new()
|
|||
|
{
|
|||
|
var RequredType = typeof(T);
|
|||
|
|
|||
|
return (List<T>?)_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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|