mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
30 lines
887 B
C#
30 lines
887 B
C#
![]() |
using System;
|
|||
|
using System.Linq;
|
|||
|
using System.Reflection;
|
|||
|
using AutoMapper;
|
|||
|
|
|||
|
namespace ModernKeePass.Application.Common.Mappings
|
|||
|
{
|
|||
|
public class MappingProfile : Profile
|
|||
|
{
|
|||
|
public MappingProfile()
|
|||
|
{
|
|||
|
ApplyMappingsFromAssembly(Assembly.GetExecutingAssembly());
|
|||
|
}
|
|||
|
|
|||
|
private void ApplyMappingsFromAssembly(Assembly assembly)
|
|||
|
{
|
|||
|
var types = assembly.GetExportedTypes()
|
|||
|
.Where(t => t.GetInterfaces().Any(i =>
|
|||
|
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>)))
|
|||
|
.ToList();
|
|||
|
|
|||
|
foreach (var type in types)
|
|||
|
{
|
|||
|
var instance = Activator.CreateInstance(type);
|
|||
|
var methodInfo = type.GetMethod("Mapping");
|
|||
|
methodInfo?.Invoke(instance, new object[] { this });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|