Beispiel #1
0
        private void RegisterCustomMappings(IEnumerable <Type> types, AutoMapperProfile profile)
        {
            var customMappings = types.Where(t =>
                                             t.IsClass &&
                                             !t.IsAbstract &&
                                             !t.IsInterface &&
                                             typeof(IHaveCustomMappings).IsAssignableFrom(t))
                                 .Select(t => (IHaveCustomMappings)Activator.CreateInstance(t))
                                 .ToList();

            foreach (var mapping in customMappings)
            {
                mapping.ConfigureMappings(this);
            }
        }
Beispiel #2
0
        private void RegisterStandartMappings(IEnumerable <Type> types, AutoMapperProfile profile)
        {
            var standartMappings = types
                                   .Select(t => new
            {
                Destination = t,
                Source      = t.GetInterfaces()
                              .First(i => i.GetGenericTypeDefinition() == typeof(IMapFrom <>))
                              .GetGenericArguments()
                              .First()
            })
                                   .ToList();

            foreach (var mapping in standartMappings)
            {
                this.CreateMap(mapping.Source, mapping.Destination);
            }
        }