I got the code from the given link
AutoMapper Code for Open Closed Principle Code
I am trying to use it in my project but I am stuck due to Static API has been removed from AutoMapper version 4.2.0. For reference see this
Please can any one help me how to implement the below code's in latest version of Automapper.
Mapper.CreateMap(TSource, TDestination)
private void RegisterStandardMappings(IEnumerable<Type> types) { var maps = (from t in types from i in t.GetInterfaces() where i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapForm<>) && !t.IsAbstract && !t.IsInterface select new { Source = i.GetGenericArguments()[0], Destination = t }).ToArray(); foreach (var map in maps) { //Need to optimize below line with current version. Mapper.CreateMap(map.Source, map.Destination); } }
Getting
IConfiguration
as it has been changed toIConfigurationProvider
private void ReverseCustomMappings(IEnumerable<Type> types) { var maps = (from t in types from i in t.GetInterfaces() where typeof(IHaveCustomMappings).IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface select (IHaveCustomMappings)Activator.CreateInstance(t)).ToArray(); foreach (var map in maps) { //Need to optimize below line with current version. map.CreateMappings(Mapper.Configuration); } } public interface IHaveCustomMappings { void CreateMappings(IConfiguration configuration); }
Please need your suggestions - any help with appreciated.