46 lines
1.0 KiB
C#
46 lines
1.0 KiB
C#
|
using SewingDressesContracts.StoragesContracts;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace SewingDressesFileImplement.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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|