protected override void MapToModel(IMappingExpression <AccountEditViewModel, MembershipUser> map) { map.ForAllMembers(n => n.Ignore()); map.ForMember(n => n.FirstName, e => e.MapFrom(u => u.FirstName)); map.ForMember(n => n.LastName, e => e.MapFrom(u => u.LastName)); map.ForMember(n => n.PhoneNumber, e => e.MapFrom(u => u.Phone)); }
public static IMappingExpression <TSource, TDestination> IgnoreAllUnmapped <TSource, TDestination>( this IMappingExpression <TSource, TDestination> expression) { expression.ForAllMembers(opt => opt.Ignore()); return(expression); }
/// <summary> /// This is used to filter out all properties that have a [DoNotCopyBackToDatabase] attribute. /// </summary> /// <param name="mappingExpression"></param> /// <returns></returns> public static IMappingExpression <TDto, TEntity> IgnoreMarkedProperties <TDto, TEntity> (this IMappingExpression <TDto, TEntity> mappingExpression) { mappingExpression.ForAllMembers(x => x.Condition(mapContext => mapContext.PropertyMap.SourceMember != null && mapContext.PropertyMap.SourceMember.GetCustomAttribute <DoNotCopyBackToDatabaseAttribute>() == null)); return(mappingExpression); }
public static IMappingExpression <TSource, TDest> IgnoreMappingOnNullValue <TSource, TDest>(this IMappingExpression <TSource, TDest> expression) { expression.ForAllMembers(opt => opt.Condition((source, destination, sourceMember, destMember, cond) => sourceMember != null )); return(expression); }
/// <summary> /// Ignores all members. /// </summary> /// <typeparam name="TSrc">The type of the source.</typeparam> /// <typeparam name="TDest">The type of the dest.</typeparam> /// <param name="mapping">The mapping.</param> /// <returns></returns> public static IMappingExpression <TSrc, TDest> IgnoreAllMembers <TSrc, TDest>(this IMappingExpression <TSrc, TDest> mapping) where TSrc : class where TDest : class { mapping .ForAllMembers(opt => opt.Ignore()); return(mapping); }
public static void OnlyOptionals <TSource, TDestination>( this IMappingExpression <TSource, TDestination> mappingExpression) { mappingExpression.ForAllMembers(mo => mo.Condition(f => { var opt = f.SourceValue as IOptional; return(opt == null || opt.HasBeenSet); })); }
/// <summary> /// Метод обработки условии к доступу данных /// </summary> private static void DataAccessCondition <TSource, TDestionation>( IMappingExpression <TSource, TDestionation> mapping) where TSource : IStatUnitM where TDestionation : IStatisticalUnit => mapping.ForAllMembers(v => v.Condition((src, dst) => { var name = DataAccessAttributesHelper.GetName(dst.GetType(), v.DestinationMember.Name); return(DataAccessAttributesProvider.Find(name) == null || (src.DataAccess?.HasWritePermission(name) ?? false)); }));
public IMappingExpression AdditionConfig(IMappingExpression mappingExpression, Type sourceType) { //忽略默认值 if (sourceType.IsDefined(typeof(MapIgnoreNullMemberAttribute), false)) { //TODO DateTime,Bool 的默认值无法忽略 mappingExpression.ForAllMembers(opt => opt.Condition((srcType, desType, srcMember, disMember) => srcMember != null && !srcMember.Equals(GetDefaultValue(sourceType)))); } return(mappingExpression); }
public static IMappingExpression <TSource, TDestination> MapOnlyIfChanged <TSource, TDestination>(this IMappingExpression <TSource, TDestination> map) { map.ForAllMembers(source => { source.Condition((sourceObject, destObject, sourceProperty, destProperty) => { if (sourceProperty == null) { return(destProperty != null); } return(!sourceProperty.Equals(destProperty)); }); }); return(map); }
public static IMappingExpression <TSource, TDestination> MapOnlyIfDirty <TSource, TDestination>( this IMappingExpression <TSource, TDestination> map) { map.ForAllMembers(source => { source.Condition((s, d, sv, dv, rc) => { if (sv == null) { return(dv != null); } return(!sv.Equals(dv)); }); }); return(map); }
public static IMappingExpression <TSource, TDestination> IgnoreNestedRevisioEntites <TSource, TDestination>(this IMappingExpression <TSource, TDestination> map) { map.ForAllMembers(source => { source.Condition((sourceObject, destObject, sourceProperty, destProperty) => { if (sourceProperty is VersionDTO || destProperty is VersionDTO || sourceProperty is Revision || destProperty is Revision) { return(false); } return(true); }); }); return(map); }
/// <summary> /// 映射指定属性的值,除此之外全部忽略 /// </summary> /// <typeparam name="TSource">source</typeparam> /// <typeparam name="TKey">key</typeparam> /// <typeparam name="TDestination">dto</typeparam> /// <param name="destinationMember">member(dto)</param> /// <param name="expression">keys</param> /// <returns></returns> public static IMappingExpression <TSource, TDestination> SetWithinProperties <TSource, TKey, TDestination>(this IMappingExpression <TSource, TDestination> destinationMember, params Expression <Func <TSource, TKey> >[] expression) { return(destinationMember); var destProperties = typeof(TDestination) .GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(w => w.CanRead && w.CanWrite); var withinFields = lambdaFields(expression); destinationMember.ForAllMembers(opts => opts.Ignore()); foreach (var destProperty in destProperties) { destinationMember.ForMember(destProperty.Name, opts => opts.MapFrom(destProperty.Name)); } return(destinationMember); }
public static IMappingExpression <TSource, TDestination> IgnoreNullAndDefault <TSource, TDestination> (this IMappingExpression <TSource, TDestination> expression) { expression.ForAllMembers(opts => opts.Condition((src, dest, srcMember) => { if (srcMember == null) { return(false); } var type = srcMember.GetType(); if (type == typeof(bool)) { return(true); } return(!srcMember.Equals(type.GetDefaultValue())); })); return(expression); }
public static IMappingExpression <TSource, TDestination> MapOnlyIfChanged <TSource, TDestination>(this IMappingExpression <TSource, TDestination> map, string EntityNameForRightsChecking = null) { map.ForAllMembers(source => { source.Condition((sourceObject, destObject, sourceProperty, destProperty, context) => { if (EntityNameForRightsChecking != null) { } if (sourceProperty == null) { return(!(destProperty == null)); } return(!sourceProperty.Equals(destProperty)); }); }); return(map); }
/// <summary> /// Use this method before any forMember invocation mapping definions It will clear all mappings, /// NOTE: Property names that match between two types will automatically have a map create for them, /// this is a way to clear all mappings, the only add the ones you want. /// if use /// </summary> /// <typeparam name="TSource">The type of the t source.</typeparam> /// <typeparam name="TDest">The type of the t dest.</typeparam> /// <param name="expression">The expression.</param> /// <returns>IMappingExpression<TSource, TDest>.</returns> public static IMappingExpression <TSource, TDest> ClearAllMappings <TSource, TDest>(this IMappingExpression <TSource, TDest> expression) { expression.ForAllMembers(opt => opt.Ignore()); return(expression); }
protected override void MapToEntity(IMappingExpression <MembershipUser, RegisterViewModel> map) { map.ForAllMembers(n => n.Ignore()); }
internal void ConditionsForAll() { _sourcExpression.ForAllMembers(x => x.Condition(r => _conditions.All(c => c(r)))); //указываем что все кондишены истинны }
/// <summary> /// Apply a conditional to all members so mapping only occurs if the source value is not null. /// </summary> public static IMappingExpression <TSource, TDestination> IgnoreNullSourceValues <TSource, TDestination>( this IMappingExpression <TSource, TDestination> expression) { expression.ForAllMembers(o => o.Condition(e => !e.IsSourceValueNull)); return(expression); }
/// <summary> /// Ignores null values in source /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TDest"></typeparam> /// <param name="expression"></param> /// <returns></returns> public static IMappingExpression <TSource, TDest> IgnoreNullValues <TSource, TDest>(this IMappingExpression <TSource, TDest> expression) { expression.ForAllMembers(opt => opt.Condition((src, dest, srcMember) => srcMember != null)); return(expression); }
static IMappingExpression AddPatchMapping(this IMappingExpression expr) { expr.ForAllMembers(m => m.Condition((source, target, sourceValue, targetValue) => sourceValue != null)); return(expr); }
public static IMappingExpression <TSource, TDest> IgnoreIdMap <TSource, TDest>(this IMappingExpression <TSource, TDest> expression) where TSource : DomainMessage { expression.ForAllMembers(opt => opt.Ignore()); return(expression); }
public static void IgnoreNullSourceProperties <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mapping) => mapping.ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));
public static IMappingExpression <TSource, TDestination> IgnoreAll <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression) { expression.ForAllMembers(x => x.Ignore()); return(expression); }
/// <summary> /// Ignore all source members which have a null value. /// </summary> public static void IgnoreAllNullMembers <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mappingExpression) => mappingExpression.ForAllMembers(a => a.MapFrom <IgnoreNullSourceValues <TSource, TDestination>, object>(a.DestinationMember.Name));
// Run ignore all members without all the excess lambda noise public static void IgnoreAllMembers <TSource, TDestination>( this IMappingExpression <TSource, TDestination> map) => map.ForAllMembers(o => o.Ignore());
public static void IgnoreAllMembers(this IMappingExpression map) => map.ForAllMembers(o => o.Ignore());
public static IMappingExpression <TSource, TDestination> IgnoreAll <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mapping) { mapping.ForAllMembers(opts => opts.Ignore()); return(mapping); }