コード例 #1
0
 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));
 }
コード例 #2
0
        public static IMappingExpression <TSource, TDestination> IgnoreAllUnmapped <TSource, TDestination>(
            this IMappingExpression <TSource, TDestination> expression)
        {
            expression.ForAllMembers(opt => opt.Ignore());

            return(expression);
        }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 /// <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);
 }
コード例 #6
0
ファイル: MappingExpression.cs プロジェクト: mgazza/Optional
 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);
     }));
 }
コード例 #7
0
 /// <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));
 }));
コード例 #8
0
 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);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 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);
 }
コード例 #11
0
 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);
 }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
 /// <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&lt;TSource, TDest&gt;.</returns>
 public static IMappingExpression <TSource, TDest> ClearAllMappings <TSource, TDest>(this IMappingExpression <TSource, TDest> expression)
 {
     expression.ForAllMembers(opt => opt.Ignore());
     return(expression);
 }
コード例 #16
0
 protected override void MapToEntity(IMappingExpression <MembershipUser, RegisterViewModel> map)
 {
     map.ForAllMembers(n => n.Ignore());
 }
コード例 #17
0
 internal void ConditionsForAll()
 {
     _sourcExpression.ForAllMembers(x => x.Condition(r => _conditions.All(c => c(r))));    //указываем что все кондишены истинны
 }
コード例 #18
0
 /// <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);
 }
コード例 #19
0
 /// <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);
 }
コード例 #20
0
 static IMappingExpression AddPatchMapping(this IMappingExpression expr)
 {
     expr.ForAllMembers(m => m.Condition((source, target, sourceValue, targetValue) => sourceValue != null));
     return(expr);
 }
コード例 #21
0
 public static IMappingExpression <TSource, TDest> IgnoreIdMap <TSource, TDest>(this IMappingExpression <TSource, TDest> expression)
     where TSource : DomainMessage
 {
     expression.ForAllMembers(opt => opt.Ignore());
     return(expression);
 }
コード例 #22
0
 public static void IgnoreNullSourceProperties <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mapping) =>
 mapping.ForAllMembers(opts => opts.Condition((src, dest, srcMember) => srcMember != null));
コード例 #23
0
 public static IMappingExpression <TSource, TDestination> IgnoreAll <TSource, TDestination>(this IMappingExpression <TSource, TDestination> expression)
 {
     expression.ForAllMembers(x => x.Ignore());
     return(expression);
 }
コード例 #24
0
 /// <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));
コード例 #25
0
 // 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());
コード例 #26
0
 public static void IgnoreAllMembers(this IMappingExpression map) =>
 map.ForAllMembers(o => o.Ignore());
コード例 #27
0
 public static IMappingExpression <TSource, TDestination> IgnoreAll <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mapping)
 {
     mapping.ForAllMembers(opts => opts.Ignore());
     return(mapping);
 }