public IActionResult Index(string searchString = "") { _logger.LogInformation($"Getting Customers' List, search by {searchString}, user: {User.Identity.Name}"); try { _clientIndexMapper = _entityMapperContextBase.Set <Point, Client>(cfg => { cfg.CreateMap <Point, Client>() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.PointNumber)) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.NamePoint)) .ForMember(dest => dest.GroupName, opt => opt.MapFrom(src => src.CliGroup.CliGroupName)) .ForMember(dest => dest.ContactName, opt => opt.MapFrom(src => src.ContactPerson)) .ForMember(dest => dest.PhoneNumber, opt => opt.MapFrom(src => src.Telefon)) .ForMember(dest => dest.Balance, opt => opt.MapFrom(src => src.Saldo)); } ); } catch (Exception ex) { _logger.LogError($"Mapping error: {ex.Message}"); } IEnumerable <Client> clients; var model = new ClientsIndexViewModel(); if (!string.IsNullOrEmpty(searchString)) { model.SearchString = string.Concat(searchString.ToCharArray().Where(c => !Char.IsWhiteSpace(c))); clients = _context.Set <Point>() .GetAll() //.FindBy(p => p.CliGroupNumber == 7 || p.CliGroupNumber == 2) ?.Where(p => p.NamePoint.ToLower().Contains(searchString.ToLower())) ?.Include(e => e.CliGroup) ?.Select(c => _clientIndexMapper.Map(c)) ?.OrderBy(c => c.GroupName) .ThenBy(c => c.Name); } else { clients = _context.Set <Point>() .GetAll() //?.FindBy(p => p.CliGroupNumber == 7 || p.CliGroupNumber == 2) ?.Include(e => e.CliGroup) ?.Select(c => _clientIndexMapper.Map(c)) ?.OrderBy(c => c.GroupName) .ThenBy(c => c.Name); } if (clients != null) { model.Clients = clients; return(View(model)); } else { _logger.LogWarning("Customers NOT FOUND!"); return(NotFound("Клиенты не найдены")); } }
/// <summary> /// Sets the <see cref="IEntityMapperBase"/> to map complex types. /// </summary> /// <param name="mapper">The <see cref="IEntityMapperBase"/> (must be <see cref="IODataMapper"/>).</param> /// <returns>The <see cref="PropertyMapperCustomBase{TSrce, TSrceProperty}"/>.</returns> public new ODataPropertyMapper<TSrce, TSrceProperty> SetMapper(IEntityMapperBase mapper) { if (mapper != null && !(mapper is IODataMapper)) throw new ArgumentException("Mapper must be instance of IODataMapper.", nameof(mapper)); base.SetMapper(mapper); return this; }
public IActionResult ClientPaymentDetails(int id) { _logger.LogInformation($"Getting Customer PAYMENT DETAILS INFO, ID: {id}, user: {User.Identity.Name}"); try { _clientPaymentDetailsMapper = _entityMapperContextBase.Set <Point, ClientPaymentDetailsEditViewModel>(cfg => { cfg.CreateMap <Point, ClientPaymentDetailsEditViewModel>() .ForMember(dest => dest.FiscalNumber, opt => opt.MapFrom(src => src.IndNum)) .ForMember(dest => dest.Certificate, opt => opt.MapFrom(src => src.SvidNum)); } ); } catch (Exception ex) { _logger.LogError($"Mapping error: {ex.Message}"); } var model = _context.Set <Point>() .FindBy(p => p.PointNumber == id) .Select(c => _clientPaymentDetailsMapper.Map(c)) .FirstOrDefault(); if (model != null) { model.Id = id; var contractors = _context.Set <Point>() .FindBy(p => p.Post == false) ?.Select(p => new ContractorDto { Id = p.PointNumber, Name = p.NamePoint }); if (contractors != null) { model.Contractors = contractors.ToList(); } return(PartialView(model)); } else { _logger.LogWarning($"Customer with ID: {id} NOT FOUND!"); return(NotFound($"Клиент с id: {id} не найден.")); } }
/// <summary> /// Sets the <see cref="IEntityMapperBase"/> to map complex types. /// </summary> /// <param name="mapper">The <see cref="IEntityMapperBase"/>.</param> /// <returns>The <see cref="PropertyMapperCustomBase{TSrce, TSrceProperty}"/>.</returns> /// <remarks>The <see cref="Mapper"/> and <see cref="Converter"/> are mutually exclusive.</remarks> public PropertyMapperCustomBase <TSrce, TSrceProperty> SetMapper(IEntityMapperBase mapper) { if (Converter != null && mapper != null) { throw new MapperException("The Mapper and Converter cannot be both set; only one is permissible."); } if (mapper != null) { if (!IsSrceComplexType) { throw new MapperException($"The PropertyMapper SrceType '{typeof(TSrceProperty).Name}' must be a complex type to set a Mapper."); } if (mapper.SrceType != SrceComplexTypeReflector.ItemType) { throw new MapperException($"The PropertyMapper SrceType '{typeof(TSrceProperty).Name}' has an ItemType of '{SrceComplexTypeReflector.ItemType.Name}' which must be the same as the underlying EntityMapper SrceType '{mapper.SrceType.Name}'."); } } Mapper = mapper; return(this); }
public IActionResult Edit(int id) { _logger.LogInformation($"Getting Customer, ID: {id}, user: {User.Identity.Name}"); try { _clientEditMapper = _entityMapperContextBase.Set <Point, ClientEditViewModel>(cfg => { cfg.CreateMap <Point, ClientEditViewModel>() .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.PointNumber)) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.NamePoint)); } ); } catch (Exception ex) { _logger.LogError($"Mapping error: {ex.Message}"); } var model = _context.Set <Point>() ?.FindBy(p => p.PointNumber == id) ?.Include(p => p.CliGroup) ?.Select(p => _clientEditMapper.Map(p)) ?.FirstOrDefault(); if (model != null) { // Add List of Groups to the Model IEnumerable <CliGroup> groups = _context.Set <CliGroup>() ?.FindBy(g => g.CliGroupNumber == 2 || g.CliGroupNumber == 7); model.CliGroups = groups?.ToList(); return(View(model)); } else { _logger.LogWarning($"Customer with ID: {id} NOT FOUND!"); return(NotFound($"Клиент с id: {id} не найден.")); } }
/// <summary> /// Gets from cache (or creates and adds to cache) the <see cref="IODataMapper"/> (with option to merge alternate property configuration). /// </summary> private static IODataMapper GetOrCreateMapper(Type type, Dictionary <string, MemberInfo> altProps, string overrideEntityName) { if (_cache.TryGetValue(type, out IODataMapper map)) { return(map); } lock (_lock) { if (_cache.TryGetValue(type, out map)) { return(map); } if (!type.IsClass) { throw new MapperException($"Type '{type.Name}' must be a class for auto-mapping."); } var mea = type.GetCustomAttributes(typeof(MapperEntityAttribute), true).OfType <MapperEntityAttribute>().FirstOrDefault(); map = (IODataMapper)Activator.CreateInstance(typeof(ODataMapper <>).MakeGenericType(type), (overrideEntityName ?? mea?.Name) ?? type.Name); var pe = Expression.Parameter(type, "x"); string dname = null; var hasProperties = false; MapperPropertyAttribute mpa = null; foreach (var p in TypeReflector.GetProperties(type)) { // Do not auto-map where the Ignore attribute has been specified. if (p.GetCustomAttributes(typeof(MapperIgnoreAttribute), true).OfType <MapperIgnoreAttribute>().FirstOrDefault() != null) { continue; } // Get property merge config. if (altProps == null) { mpa = p.GetCustomAttributes(typeof(MapperPropertyAttribute), true).OfType <MapperPropertyAttribute>().FirstOrDefault(); dname = mpa?.Name; } else { if (!altProps.TryGetValue(p.Name, out MemberInfo alt)) { throw new InvalidOperationException($"Type '{type.Name}' Property '{p.Name}' does not have an alternative property configuration specified."); } // Do not auto-map where the Ignore attribute has been specified. if (alt.GetCustomAttributes(typeof(MapperIgnoreAttribute), true).OfType <MapperIgnoreAttribute>().FirstOrDefault() != null) { continue; } mpa = alt.GetCustomAttributes(typeof(MapperPropertyAttribute), true).OfType <MapperPropertyAttribute>().FirstOrDefault(); dname = mpa?.Name ?? alt.Name; } // Create the lambda expression for the property and add to the mapper. hasProperties = true; var lex = Expression.Lambda(Expression.Property(pe, p.Name), pe); var pmap = (IODataPropertyMapper)map.GetType() .GetMethod("Property", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly) .MakeGenericMethod(p.PropertyType) .Invoke(map, new object[] { lex, dname, mpa == null ? OperationTypes.Any : mpa.OperationTypes }); if (mpa == null) { continue; } // Apply auto-map Property attribute IsUnique configuration. if (mpa.IsUniqueKey) { pmap.SetUniqueKey(mpa.IsUniqueKeyAutoGeneratedOnCreate); } // Apply auto-map Property attribute ConverterType configuration. if (mpa.ConverterType != null) { if (!typeof(IPropertyMapperConverter).IsAssignableFrom(mpa.ConverterType)) { throw new MapperException($"Type '{type.Name}' Property '{p.Name}' has 'MapperPropertyAttribute' with ConverterType set to '{mpa.ConverterType.Name}' which does not implement 'IPropertyMapperConverter'."); } IPropertyMapperConverter pmc = null; var pdef = mpa.ConverterType.GetProperty("Default", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); if (pdef == null) { if (mpa.ConverterType.GetConstructor(Type.EmptyTypes) == null) { throw new MapperException($"Type '{type.Name}' Property '{p.Name}' has 'MapperPropertyAttribute' with ConverterType set to '{mpa.ConverterType.Name}' does not have a static 'Default' property or default constructor."); } pmc = (IPropertyMapperConverter)Activator.CreateInstance(mpa.ConverterType); } else { pmc = (IPropertyMapperConverter)pdef.GetValue(null); } pmap.SetConverter(pmc); continue; } // Apply auto-map Property attribute MapperType configuration for complex types. if (pmap.IsSrceComplexType) { IEntityMapperBase em = null; if (mpa.MapperType == null) { em = GetMapper(pmap.SrceComplexTypeReflector.ItemType); } else { if (!typeof(IEntityMapperBase).IsAssignableFrom(mpa.MapperType)) { throw new MapperException($"Type '{type.Name}' Property '{p.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.MapperType.Name}' which does not implement 'IEntityMapper'."); } var mdef = mpa.MapperType.GetProperty("Default", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); if (mdef == null) { if (mpa.ConverterType.GetConstructor(Type.EmptyTypes) == null) { throw new MapperException($"Type '{type.Name}' Property '{p.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.MapperType.Name}' does not have a static 'Default' property or default constructor."); } em = (IEntityMapperBase)Activator.CreateInstance(mpa.MapperType); } else { em = (IEntityMapperBase)mdef.GetValue(null); } } if (em != null) { pmap.SetMapper(em); } } else if (mpa.MapperType != null) { throw new MapperException($"Type '{type.Name}' Property '{p.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.ConverterType.Name}' although the property is not a complex type."); } } if (!hasProperties) { throw new MapperException($"AutoMapper has found no properties for Type '{type.Name}' that it is able to auto-map."); } _cache.Add(type, map); return(map); } }
public IActionResult ClientDebtDetails(int id) { _logger.LogInformation($"Getting Customer DEBT DETAILS INFO, ID: {id}, user: {User.Identity.Name}"); try { _clientDebtDetailsMapper = _entityMapperContextBase.Set <Point, ClientDebtDetailsEditViewModel>(cfg => { cfg.CreateMap <Point, ClientDebtDetailsEditViewModel>() .ForMember(dest => dest.BillSettings, opt => opt.MapFrom(src => src.BillSettingsInfo)) .ForMember(dest => dest.DebtControl, opt => opt.MapFrom(src => src.DebtControlInfo)) .ForMember(dest => dest.FranchisingTypeId, opt => opt.MapFrom(src => src.FranchisingInfo.FranchisingTypeId)) .ForMember(dest => dest.DebtCalcMethodTypeId, opt => opt.MapFrom(src => src.DebtCalcMethodInfo.DebtCalcMethodTypeId)) .ForMember(dest => dest.ClientConnection, opt => opt.MapFrom(src => src.ClientConnectionInfo)) .ForMember(dest => dest.BillOptionsAll, opt => opt.MapFrom(src => src.BillOptionsInfo)) .ForMember(dest => dest.PrintJobsAll, opt => opt.MapFrom(src => src.PrintJobInfo)) .ForMember(dest => dest.BillSettings, opt => opt.Condition(src => src.BillSettingsInfo != null)) .ForMember(dest => dest.DebtControl, opt => opt.Condition(src => src.DebtControlInfo != null)) .ForMember(dest => dest.FranchisingTypeId, opt => opt.Condition(src => src.FranchisingInfo != null)) .ForMember(dest => dest.DebtCalcMethodTypeId, opt => opt.Condition(src => src.DebtCalcMethodInfo != null)) .ForMember(dest => dest.ClientConnection, opt => opt.Condition(src => src.ClientConnectionInfo != null)) .ForMember(dest => dest.BillOptionsAll, opt => opt.Condition(src => src.BillOptionsInfo != null)) .ForMember(dest => dest.PrintJobsAll, opt => opt.Condition(src => src.PrintJobInfo != null)) ; cfg.CreateMap <PrintJobInfo, PrintJobDto>(); cfg.CreateMap <BillOptionsInfo, BillOptionsDto>(); }); } catch (Exception ex) { _logger.LogError($"Mapping error: {ex.Message}"); } var clients = _context.Set <Point>() ?.FindBy(p => p.PointNumber == id) ?.Include(p => p.BillSettingsInfo) ?.Include(p => p.BillOptionsInfo) ?.Include(p => p.PrintJobInfo) ?.Include(p => p.DebtControlInfo) ?.Include(p => p.DebtCalcMethodInfo) ?.Include(p => p.FranchisingInfo) ?.Include(p => p.ClientConnectionInfo); if (clients?.FirstOrDefault() != null) { var client = clients.FirstOrDefault(); var model = _clientDebtDetailsMapper.Map(client); model.Id = id; // Check all properties for null (i.e not mapped subject to Mapping Condition) model.DebtControl = model.DebtControl ?? new DebtControlDto(); model.BillSettings = model.BillSettings ?? new BillSettingsDto(); model.ClientConnection = model.ClientConnection ?? new ClientConnectionDto(); model.BillOptionsAll = model.BillOptionsAll ?? new List <BillOptionsDto>(); model.PrintJobsAll = model.PrintJobsAll ?? new List <PrintJobDto>(); // DebtCalc Method Types var debtCalcMethodsAll = _context.Set <DebtCalcMethodType>() .GetAll() ?.Select(d => new DebtCalcMethodTypeDto { DebtCalcMethodTypeId = d.DebtCalcMethodTypeId, Name = d.Name }) ?.ToList(); model.DebtCalcMethodsAll = debtCalcMethodsAll ?? new List <DebtCalcMethodTypeDto>(); // Add items into PrintJobsAll if its Count < PrintJobsCapacity for (int i = 0; i < model.PrintJobsCapacity; i++) { if (model.PrintJobsAll.ElementAtOrDefault(i) == null) { model.PrintJobsAll.Add(new PrintJobDto { DocumentToPrintCopies = 0 }); } else { model.PrintJobsAll[i].Active = true; } } // Add items into BillOptionsAll if its Count < BillOptionsCapacity for (int i = 0; i < model.BillOptionsCapacity; i++) { if (model.BillOptionsAll.ElementAtOrDefault(i) == null) { model.BillOptionsAll.Add(new BillOptionsDto { Limit = 0 }); } else { model.BillOptionsAll[i].Active = true; } } // Franchising Types var franchisingTypesAll = _context.Set <FranchisingType>() .GetAll() ?.Select(d => new FranchisingTypeDto { Name = d.Name, FranchisingTypeId = d.FranchisingTypeId }) ?.ToList(); model.FranchisingTypesAll = franchisingTypesAll ?? new List <FranchisingTypeDto>(); // Franchising Clients if (_context.Set <FranchisingInfo>().GetAll().Count() > 0) { model.FranchisingClients = _context.Set <Point>() .GetAll() ?.Include(p => p.FranchisingInfo) ?.Select(d => new FranchisingClientDto { FranchisingClientDtoId = d.FranchisingInfo.PointNumber, Name = d.NamePoint }) ?.ToList() ?? model.FranchisingClients; } // DocumentTemplates model.DocumentTemplatesAll = _context.Set <DocumentTemplate>() .GetAll() ?.Select(d => new DocumentTemplateDto { DocumentTemplateId = d.DocumentTemplateId, Name = d.Name }) ?.ToList() ?? model.DocumentTemplatesAll; //// Check all other properties here..... return(PartialView(model)); } else { _logger.LogWarning($"Customer with ID: {id} NOT FOUND!"); return(NotFound($"Клиент с id: {id} не найден.")); } }
public IActionResult ClientContacts(int id) { _logger.LogInformation($"Getting Customer CONTACT INFO, ID: {id}, user: {User.Identity.Name}"); try { _clientContactsMapper = _entityMapperContextBase.Set <Point, ClientContactsEditViewModel>(cfg => { cfg.CreateMap <Point, ClientContactsEditViewModel>() .ForMember(dest => dest.LegalAddress, opt => opt.MapFrom(src => src.Address)) .ForMember(dest => dest.PhoneNumber1, opt => opt.MapFrom(src => src.Telefon)) .ForMember(dest => dest.ContactFullName1, opt => opt.MapFrom(src => src.ContactPerson)) .ForMember(dest => dest.Email1, opt => opt.MapFrom(src => src.Email)) .ForMember(dest => dest.FirstSignatory, opt => opt.MapFrom(src => src.Name1Person)) .ForMember(dest => dest.SecondSignatory, opt => opt.MapFrom(src => src.Name2Person)) .ForMember(dest => dest.ContactPhonesAll, opt => opt.MapFrom(src => src.ContactPhoneInfo)) .ForMember(dest => dest.ContactEmailsAll, opt => opt.MapFrom(src => src.ContactEmailInfo)); } ); } catch (Exception ex) { _logger.LogError($"Mapping error: {ex.Message}"); } var model = _context.Set <Point>() .FindBy(p => p.PointNumber == id) ?.Include(p => p.ContactPhoneInfo) ?.Include(p => p.ContactEmailInfo) ?.Select(c => _clientContactsMapper.Map(c)) ?.FirstOrDefault(); if (model != null) { model.Id = id; // Fill ContactPhonesView for (int i = 0; i < model.ContactPhonesCapacity; i++) { if (model.ContactPhonesAll.ElementAtOrDefault(i) != null) { model.ContactPhonesView.Add(model.ContactPhonesAll.ElementAtOrDefault(i)); } else { model.ContactPhonesView.Add(new ContactPhoneDto { PhoneNumber = string.Empty, ContactFullName = string.Empty }); } } // Fill ContactEmailsView for (int i = 0; i < model.ContactEmailsCapacity; i++) { if (model.ContactEmailsAll.ElementAtOrDefault(i) != null) { model.ContactEmailsView.Add(model.ContactEmailsAll.ElementAtOrDefault(i)); } else { model.ContactEmailsView.Add(new ContactEmailDto { Email = string.Empty, IncludeToMailList = false }); } } return(PartialView(model)); } else { _logger.LogWarning($"Customer with ID: {id} NOT FOUND!"); return(NotFound($"Клиент с id: {id} не найден.")); } }
/// <summary> /// Sets the <see cref="IEntityMapperBase"/> to map complex types. /// </summary> /// <param name="mapper">The <see cref="IEntityMapperBase"/>.</param> /// <remarks>The <see cref="Mapper"/> and <see cref="Converter"/> are mutually exclusive.</remarks> void IPropertyMapperBase.SetMapper(IEntityMapperBase mapper) { SetMapper(mapper); }
public IActionResult CreateTicket() { _clientMapper = _entityMapperContextBase.Set <Point, ClientDto>(cfg => { cfg.CreateMap <Point, ClientDto>() .ForMember(dest => dest.ClientId, opt => opt.MapFrom(src => src.PointNumber)) .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.NamePoint)); }); var clients = _context.Set <Point>() ?.FindBy(p => p.CliGroupNumber == 7 || p.CliGroupNumber == 2) ?.Include(c => c.CliGroup) ?.OrderBy(c => c.NamePoint) ?.Select(enity => _clientMapper.Map(enity)); if (clients != null) { TicketCreateViewModel model = new TicketCreateViewModel(); // Clients model.Clients = clients.ToList(); // Communication types var communicationTypes = _context.Set <PointCommunicationType>() ?.GetAll() ?.Select(pct => new PointCommunicationTypeDto { PointCommunicationTypeId = pct.PointCommunicationTypeId, Name = pct.Name }); model.PointCommunicationTypes = communicationTypes?.ToList() ?? model.PointCommunicationTypes; //додавання типу заявок (категорія) IQueryable <TicketSubjectDto> subjectsParents = _context.Set <TicketSubject>() ?.GetAll() ?.Where(t => t.ParentId == null) ?.Select(t => new TicketSubjectDto { Name = t.TicketSubjectName, TicketSubjectId = t.TicketSubjectId }); //підкатегорія (тема) //IQueryable<TicketSubjectDto> subjectFirstChildren = _context.Set<TicketSubject>() // ?.GetAll() // ?.Where(t => t.ParentId != null) // ?.Select(t => new TicketSubjectDto // { // Name = t.TicketSubjectName, // TicketSubjectId = t.TicketSubjectId // }); //model.TicketSubjectFirstChildren = subjectFirstChildren?.ToList() ?? model.TicketSubjectFirstChildren; model.TicketSubjectParents = subjectsParents?.ToList() ?? model.TicketSubjectParents; //TMP! model.TicketSubjectLastChildren = _context.Set <TicketSubject>() ?.GetAll() ?.Where(i => i.ParentId == 16) ?.Select(s => new TicketSubjectOptionDto { Active = false, Name = s.TicketSubjectName, TicketSubjectId = s.TicketSubjectId }).ToList(); //END TMP return(View(model)); } return(NotFound("Ticket Subjects are not found!")); }
public ServiceBase(IRepositoryContextBase repositoryContext, IEntityMapperBase <TEntity, TDTO> entityMapper) { _repository = repositoryContext.Set <TEntity>(); _entityMapper = entityMapper; }
/// <summary> /// Automatically map commonly named properties. /// </summary> private void AutomagicallyMap(string[] ignoreSrceProperties) { MapperPropertyAttribute mpa = null; foreach (var sp in SrceType.GetProperties(BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance)) { // Do not auto-map where ignore has been specified. if (ignoreSrceProperties.Contains(sp.Name)) { continue; } if (sp.GetCustomAttributes(typeof(MapperIgnoreAttribute), true).OfType <MapperIgnoreAttribute>().FirstOrDefault() != null) { continue; } // Find corresponding property. mpa = sp.GetCustomAttributes(typeof(MapperPropertyAttribute), true).OfType <MapperPropertyAttribute>().FirstOrDefault(); var dname = mpa == null || string.IsNullOrEmpty(mpa.Name) ? sp.Name : mpa.Name; var dp = DestType.GetProperty(dname, BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.Instance); if (dp == null) { if (mpa != null) { throw new InvalidOperationException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with Name set to '{dname}' which does not exist for destination Type '{DestType.Name}'."); } continue; } // Create the lambda expressions for the property and add to the mapper. var spe = Expression.Parameter(SrceType, "x"); var sex = Expression.Lambda(Expression.Property(spe, sp.Name), spe); var dpe = Expression.Parameter(DestType, "x"); var dex = Expression.Lambda(Expression.Property(dpe, dname), dpe); var pmap = (IPropertyMapper <TSrce, TDest>) typeof(EntityMapper <TSrce, TDest>) .GetMethod("PropertySrceAndDest", BindingFlags.NonPublic | BindingFlags.Instance) .MakeGenericMethod(new Type[] { sp.PropertyType, dp.PropertyType }) .Invoke(this, new object[] { sex, dex }); if (mpa == null) { continue; } // Apply auto-map Property attribute IsUnique configuration. if (mpa.IsUniqueKey) { pmap.SetUniqueKey(mpa.IsUniqueKeyAutoGeneratedOnCreate); } // Apply auto-map Property attribute ConverterType configuration. if (mpa.ConverterType != null) { if (!typeof(IPropertyMapperConverter).IsAssignableFrom(mpa.ConverterType)) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with ConverterType set to '{mpa.ConverterType.Name}' which does not implement 'IPropertyMapperConverter'."); } IPropertyMapperConverter pmc = null; var pdef = mpa.ConverterType.GetProperty("Default", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); if (pdef == null) { if (mpa.ConverterType.GetConstructor(Type.EmptyTypes) == null) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with ConverterType set to '{mpa.ConverterType.Name}' does not have a static 'Default' property or default constructor."); } pmc = (IPropertyMapperConverter)Activator.CreateInstance(mpa.ConverterType); } else { pmc = (IPropertyMapperConverter)pdef.GetValue(null); } pmap.SetConverter(pmc); continue; } // Apply auto-map Property attribute MapperType configuration for complex types. if (pmap.IsSrceComplexType) { IEntityMapperBase em = null; if (mpa.MapperType != null) { if (!typeof(IEntityMapperBase).IsAssignableFrom(mpa.MapperType)) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.MapperType.Name}' which does not implement 'IEntityMapper'."); } var mdef = mpa.MapperType.GetProperty("Default", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static); if (mdef == null) { if (mpa.ConverterType.GetConstructor(Type.EmptyTypes) == null) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.MapperType.Name}' does not have a static 'Default' property or default constructor."); } em = (IEntityMapperBase)Activator.CreateInstance(mpa.MapperType); } else { em = (IEntityMapperBase)mdef.GetValue(null); } } if (em != null) { pmap.SetMapper(em); } } else if (mpa.MapperType != null) { throw new MapperException($"Type '{SrceType.Name}' Property '{sp.Name}' has 'MapperPropertyAttribute' with MapperType set to '{mpa.ConverterType.Name}' although the property is not a complex type."); } } }