48 lines
1.3 KiB
C#

using DressAtelierContracts.StorageContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace DressAtelierFileImplement.Implements
{
public class BackupInfo : IBackupInfo
{
public List<T>? GetList<T>() where T : class, new()
{
List<T>? list = new();
var source = DataFileSingleton.GetInstance();
Type typeRequired = typeof(T);
Type typeSource = source.GetType();
foreach(var property in typeSource.GetProperties())
{
if (property.PropertyType.IsGenericType && property.PropertyType.GetGenericArguments()[0] == typeRequired)
{
list.Add((T)property.GetValue(source));
}
}
return list;
}
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;
}
}
}