public static IMappingExpression <TSource, TDest> IgnoreAllUnmapped <TSource, TDest>(this IMappingExpression <TSource, TDest> expression) { expression.ForAllMembers(opt => opt.Ignore()); return(expression); }
public static void MapSpecifiedFields <TSource, TDest>(IMappingExpression <TSource, TDest> mappingExpression) { throw new NotImplementedException("Not yet"); }
public static IMappingExpression <TSource, TDestination> Ignore <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mappingExpression, Expression <Func <TDestination, object> > destination) { mappingExpression = mappingExpression.ForMember(destination, options => options.Ignore()); return(mappingExpression); }
public virtual void AdditionalSettings(IMappingExpression <BusinessObject, Persistent> map, BusinessObject objeto, UnitOfWork unit) { }
public static IMappingExpression <TSource, TDestination> MapTo <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression) { Type sourceType = typeof(TSource); Type destinationType = typeof(TDestination); TypeMap existingMaps = Mapper.GetAllTypeMaps().First(b => b.SourceType == sourceType && b.DestinationType == destinationType); string[] missingMappings = existingMaps.GetUnmappedPropertyNames(); if (missingMappings.Any()) { PropertyInfo[] sourceProperties = sourceType.GetProperties(); foreach (string property in missingMappings) { foreach (PropertyInfo propertyInfo in sourceProperties) { MapToAttribute attr = propertyInfo.GetCustomAttribute <MapToAttribute>(); if (attr != null && attr.Name == property) { expression.ForMember(property, opt => opt.ResolveUsing(new MyValueResolve(propertyInfo))); } } } } return(expression); }
public abstract void ToSource(IMappingExpression <TDestination, TSource> map);
partial void MapInputToEntity(IMappingExpression <RightInput, RightEntity> mapExpr);
public static IMappingExpression <TSource, TDestination> ToMember <TSource, TDestination, TDestinonResult, TSourceResult>(this IMappingExpression <TSource, TDestination> expression, Expression <Func <TDestination, TDestinonResult> > destinationFunc, Expression <Func <TSource, TSourceResult> > sourcefunc) { return(expression.ForMember(destinationFunc, conf => conf.MapFrom(sourcefunc))); }
public static IMappingExpression <TSource, TDestination> IgnoreMember <TSource, TDestination, TResult>(this IMappingExpression <TSource, TDestination> expression, Expression <Func <TDestination, TResult> > destinationFunc) { return(expression.ForMember(destinationFunc, conf => conf.Ignore())); }
protected override void Configure(IMappingExpression <SPTerm, TermViewModel> mapping) { mapping.ForMember(m => m.Id, o => o.ResolveUsing(t => t.Id)); mapping.ForMember(m => m.Name, o => o.ResolveUsing(t => t.Name)); mapping.ForMember(m => m.Path, o => o.ResolveUsing(t => t.Path)); }
public static IMappingExpression <TSource, TDestination> IgnoreAllNonExisting <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression) { var sourceType = typeof(TSource); //var destinationType = typeof(TDestination); //var existingMaps = Mapper.Configuration.GetAllTypeMaps().First(x => x.SourceType.Equals(sourceType) // && x.DestinationType.Equals(destinationType)); foreach (var property in sourceType.GetProperties()) { if (typeof(ICollection <Product>).IsAssignableFrom(property.PropertyType)) { } //expression.ForMember(property, opt => opt.Ignore()); } return(expression); }
public static IMappingExpression <TSource, TDestination> IgnoreAllNonExisting <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression) { var flags = BindingFlags.Public | BindingFlags.Instance; var sourceType = typeof(TSource); var destinationProperties = typeof(TDestination).GetProperties(flags); foreach (var property in destinationProperties) { if (sourceType.GetProperty(property.Name, flags) == null) { expression.ForMember(property.Name, opt => opt.Ignore()); } } return(expression); }
public override void CustomMappings(IMappingExpression <Employ, EmploySelectDto> mappingExpression) { mappingExpression.ForMember( dest => dest.Time, config => config.MapFrom(src => src.Time.ToString("d"))); }
public override void CustomMappings(IMappingExpression <Employ, EmployDto> mappingExpression) { // mappingExpression.ForMember( // dest => dest.Time, // config => config.MapFrom(src => DateTime.Now)); }
private static IMappingExpression MappingCore(IMappingExpression coreMap, Type resolveActionType, string destName, string srcName) { if (resolveActionType == null) coreMap = coreMap.ForMember(destName, map => map.MapFrom(srcName)); else coreMap = coreMap.ForMember(destName, map => map.ResolveUsing(resolveActionType).FromMember(srcName)); return coreMap; }
public void ConfigureMapping(IMappingExpression mappingExpression) { mappingExpression.ForMember(nameof(DestinationData.Name), expression => expression.MapFrom(nameof(SourceDataNormalAttribute.YetAnotherName))); }
public abstract void ToDestination(IMappingExpression <TSource, TDestination> map);
public static IMappingExpression <TSource, TDestination> Ignore <TSource, TDestination>(this IMappingExpression <TSource, TDestination> map, Expression <Func <TDestination, object> > selector) { map.ForMember(selector, config => config.Ignore()); return(map); }
public static List <IMappingExpression <TSource, TDestination> > LoadedtMappings <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression, List <ICustomMappable> mappings) { var loadedMappings = new List <IMappingExpression <TSource, TDestination> >(); var sourceProperties = typeof(TSource).GetProperties(); var destinationProperties = typeof(TDestination).GetProperties(); foreach (var map in mappings) { var sourceMap = map.Source; var destinationMap = map.Destination; PropertyInfo destinationProperty; try { destinationProperty = destinationProperties.First(p => p.Name == destinationMap); } catch (InvalidOperationException e) { throw new Exception($"Destination Property ({destinationMap}) doesn't exist... {e}"); } PropertyInfo sourceProperty = null; if (string.IsNullOrEmpty(map.Value)) { try { sourceProperty = sourceProperties.First(p => p.Name == sourceMap); } catch (InvalidOperationException e) { throw new Exception($"Source Property ({sourceMap}) doesn't exist... {e}"); } } if (map.IgnoreMapping()) { expression.ForMember(destinationProperty.Name, opt => opt.Ignore()); } else if (sourceProperty == null) { expression.ForMember(destinationProperty.Name, opt => opt.UseValue(map.Value)); } else { expression.ForMember(destinationProperty.Name, opt => opt.MapFrom(sourceProperty.Name)); } loadedMappings.Add(expression); } return(loadedMappings); }
public override void ExtendSourceToTargetMapping(IMappingExpression <AddressModel, AddressViewModel> map) { map.MapMember(t => t.FullStreetAddress, s => string.Join(", ", new List <string> { s.Street, s.City, s.State })); }
partial void MapEntityToView(IMappingExpression <RightEntity, Right> mapExpr);
public override void ExtendTargetToSourceMapping(IMappingExpression <AddressViewModel, AddressModel> map) { }
public virtual void AdditionalSettings(IMappingExpression <Persistent, BusinessObject> map, BusinessObject destination) { }
protected override void ConfigureMapping(IMappingExpression <RingModel, Ring> map) { //map.ForMember(dest => dest.PasswordData, opt => opt.MapFrom(source => Users.HashPassword(source.NewPassword))); }
public UserMapper() { CreateMap <DocEntitySet <DocEntityUser>, List <Reference> >() .ConvertUsing(s => s.ToReferences()); CreateMap <DocEntityUser, Reference>() .ConstructUsing(s => null == s || !(s.Id > 0) ? null : s.ToReference()); CreateMap <Reference, DocEntityUser>() .ForMember(dest => dest.Id, opt => opt.Condition(src => null != src && src.Id > 0)) .ConstructUsing(c => DocEntityUser.Get(c)); _EntityToDto = CreateMap <DocEntityUser, User>() .ForMember(dest => dest.Created, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, "Created"))) .ForMember(dest => dest.Updated, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, "Updated"))) .ForMember(dest => dest.ClientDepartment, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ClientDepartment)))) .ForMember(dest => dest.Division, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Division)))) .ForMember(dest => dest.DivisionId, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.DivisionId)))) .ForMember(dest => dest.DocumentSets, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.DocumentSets)))) .ForMember(dest => dest.DocumentSetsCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.DocumentSetsCount)))) .ForMember(dest => dest.DocumentSetsIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.DocumentSetsIds)))) .ForMember(dest => dest.Email, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Email)))) .ForMember(dest => dest.ExpireDate, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ExpireDate)))) .ForMember(dest => dest.FailedLoginCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.FailedLoginCount)))) .ForMember(dest => dest.FirstName, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.FirstName)))) .ForMember(dest => dest.Gravatar, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Gravatar)))) .ForMember(dest => dest.History, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.History)))) .ForMember(dest => dest.HistoryCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.HistoryCount)))) .ForMember(dest => dest.HistoryIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.HistoryIds)))) .ForMember(dest => dest.Impersonated, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Impersonated)))) .ForMember(dest => dest.ImpersonatedCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ImpersonatedCount)))) .ForMember(dest => dest.ImpersonatedIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ImpersonatedIds)))) .ForMember(dest => dest.Impersonating, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Impersonating)))) .ForMember(dest => dest.ImpersonatingCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ImpersonatingCount)))) .ForMember(dest => dest.ImpersonatingIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ImpersonatingIds)))) .ForMember(dest => dest.IsSystemUser, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.IsSystemUser)))) .ForMember(dest => dest.JobTitle, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.JobTitle)))) .ForMember(dest => dest.LastLogin, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.LastLogin)))) .ForMember(dest => dest.LastName, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.LastName)))) .ForMember(dest => dest.LegacyUsername, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.LegacyUsername)))) .ForMember(dest => dest.Locale, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Locale)))) .ForMember(dest => dest.LocaleId, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.LocaleId)))) .ForMember(dest => dest.LoginCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.LoginCount)))) .ForMember(dest => dest.Name, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Name)))) .ForMember(dest => dest.Roles, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Roles)))) .ForMember(dest => dest.RolesCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.RolesCount)))) .ForMember(dest => dest.RolesIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.RolesIds)))) .ForMember(dest => dest.Scopes, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Scopes)))) .ForMember(dest => dest.ScopesCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ScopesCount)))) .ForMember(dest => dest.ScopesIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.ScopesIds)))) .ForMember(dest => dest.Sessions, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Sessions)))) .ForMember(dest => dest.SessionsCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.SessionsCount)))) .ForMember(dest => dest.SessionsIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.SessionsIds)))) .ForMember(dest => dest.Settings, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Settings)))) .ForMember(dest => dest.Slack, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Slack)))) .ForMember(dest => dest.StartDate, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.StartDate)))) .ForMember(dest => dest.Status, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Status)))) .ForMember(dest => dest.Teams, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Teams)))) .ForMember(dest => dest.TeamsCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.TeamsCount)))) .ForMember(dest => dest.TeamsIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.TeamsIds)))) .ForMember(dest => dest.TimeCards, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.TimeCards)))) .ForMember(dest => dest.TimeCardsCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.TimeCardsCount)))) .ForMember(dest => dest.TimeCardsIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.TimeCardsIds)))) .ForMember(dest => dest.Updates, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Updates)))) .ForMember(dest => dest.UpdatesCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.UpdatesCount)))) .ForMember(dest => dest.UpdatesIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.UpdatesIds)))) .ForMember(dest => dest.UserType, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.UserType)))) .ForMember(dest => dest.UserTypeId, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.UserTypeId)))) .ForMember(dest => dest.Workflows, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.Workflows)))) .ForMember(dest => dest.WorkflowsCount, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.WorkflowsCount)))) .ForMember(dest => dest.WorkflowsIds, opt => opt.PreCondition(c => DocMapperConfig.ShouldBeMapped <User>(c, nameof(DocEntityUser.WorkflowsIds)))) .MaxDepth(2); _DtoToEntity = CreateMap <User, DocEntityUser>() .MaxDepth(2); ApplyCustomMaps(); }
protected override void ConfigureMapping(IMappingExpression <Ring, RingModel> map) { // Properties with matching names are mapped automatically. //map.ForMember(dest => dest.NewPassword, opt => opt.Ignore()); }
public static IMappingExpression <TServiceModel, TModel> ApplyDefaultServiceModelMappingOptions <TServiceModel, TModel>(this IMappingExpression <TServiceModel, TModel> mappingExpression) where TServiceModel : ServiceModelBase where TModel : ModelBase, new() { // try to load the destination object first in stead of creating a new instance immediately mappingExpression = mappingExpression.ConstructUsing((source, context) => { var dbContext = context.GetDbContext(); if (dbContext == null) { return(new TModel()); } var repository = dbContext.Set <TModel>(); var model = repository.FirstOrDefault(x => x.Guid == source.Guid) ?? new TModel(); model.SetUpdateFields(context.GetUserName()); return(model); }); return(mappingExpression); }
public static IMappingExpression <TSource, TDestination> IgnoreAllNonExisting <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression) { foreach (var property in expression.TypeMap.GetUnmappedPropertyNames()) { expression.ForMember(property, a => a.Ignore()); } return(expression); }
public static IMappingExpression <TModel, TServiceModel> ApplyDefaultModelMappingOptions <TModel, TServiceModel>(this IMappingExpression <TModel, TServiceModel> mappingExpression) where TServiceModel : ServiceModelBase where TModel : ModelBase { var serviceModelProperties = typeof(TServiceModel).GetProperties(); var modelProperties = typeof(TModel).GetProperties(); foreach (var propertyInfo in modelProperties) { if (typeof(ModelBase).IsAssignableFrom(propertyInfo.PropertyType)) { var serviceModelPropertyInfo = serviceModelProperties.FirstOrDefault(x => Equals(x.Name, propertyInfo.Name)); if (serviceModelPropertyInfo != null && typeof(ServiceModelBase).IsAssignableFrom(serviceModelPropertyInfo.PropertyType)) { mappingExpression.ForMember( propertyInfo.Name, options => { options.ResolveUsing((model, serviceModel, serviceModelMember, resolutionContext) => { if (IsPropertyIncluded <TServiceModel>(resolutionContext, propertyInfo.Name)) { var item = propertyInfo.GetValue(model); if (item is ModelBase modelBase) { if (modelBase.IsObsolete) { return(null); } } return(propertyInfo.GetValue(model)); } return(null); }); }); } } if (typeof(IEnumerable <ModelBase>).IsAssignableFrom(propertyInfo.PropertyType)) { var serviceModelPropertyInfo = serviceModelProperties.FirstOrDefault(x => Equals(x.Name, propertyInfo.Name)); if (serviceModelPropertyInfo != null && typeof(IEnumerable <ServiceModelBase>).IsAssignableFrom(serviceModelPropertyInfo.PropertyType)) { mappingExpression.ForMember( propertyInfo.Name, options => { options.ResolveUsing((model, serviceModel, serviceModelMember, resolutionContext) => { if (IsPropertyIncluded <TServiceModel>(resolutionContext, propertyInfo.Name)) { var items = propertyInfo.GetValue(model); if (items is IEnumerable <ModelBase> ) { items = ((IEnumerable <ModelBase>)items).Where(x => !x.IsObsolete); } return(items); } return(null); }); }); } } } return(mappingExpression.PreserveReferences()); }
public static IMappingExpression <TSource, TDestination> Ignore <TSource, TDestination>( this IMappingExpression <TSource, TDestination> mapping, Expression <Func <TDestination, object> > property) { return(mapping.ForMember(property, o => o.Ignore())); }
static IMappingExpression <TSource, TDestination> IgnoreAllNonExisting <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression) { var sourceType = typeof(TSource); var destinationType = typeof(TDestination); var existingMaps = Mapper.Configuration.GetAllTypeMaps().First(x => x.SourceType.Equals(sourceType) && x.DestinationType.Equals(destinationType)); foreach (var property in existingMaps.GetUnmappedPropertyNames()) { expression.ForMember(property, opt => opt.Ignore()); } return(expression); }
public MessagingContext(string connectionName) : base("name=" + connectionName) { messageCopier = Mapper.CreateMap<MessagePing, MessagePing>(); }