コード例 #1
0
        public static IMappingExpression <TSource, TDest> IgnoreAllUnmappedComplexTypes <TSource, TDest>(this IMappingExpression <TSource, TDest> expression)
        {
            var destType   = typeof(TDest);
            var sourceType = typeof(TSource);

            expression.ForAllOtherMembers(
                delegate(IMemberConfigurationExpression <TSource, TDest, object> configurationExpression)
            {
                var propName   = configurationExpression.DestinationMember.Name;
                var sourceProp = sourceType.GetProperties().Any(x => x.Name.EqualsIgnoreCase(propName));
                if (sourceProp)
                {
                    return;
                }

                var propType = destType.GetProperties().First(x => x.Name.EqualsIgnoreCase(propName)).PropertyType;

                if (!propType.IsValueType &&
                    !propType.IsEnum &&
                    propType != typeof(string) &&
                    propType != typeof(char[]))
                {
                    configurationExpression.Ignore();
                }
            });

            return(expression);
        }
コード例 #2
0
 public static IMappingExpression <TSource, TDestination> IgnoreNullValues <TSource, TDestination>(
     this IMappingExpression <TSource, TDestination> mapperExpression)
 {
     mapperExpression.ForAllOtherMembers(source =>
     {
         source.Condition((s, d, sourceValue, destValue, rc) =>
         {
             return(sourceValue != null);
         });
     });
     return(mapperExpression);
 }
コード例 #3
0
 /// <summary>
 /// Ignore all source members not previously configured which have a null value.
 /// </summary>
 public static void IgnoreAllOtherNullMembers <TSource, TDestination>(this IMappingExpression <TSource, TDestination> mappingExpression)
 => mappingExpression.ForAllOtherMembers(a => a.MapFrom <IgnoreNullSourceValues <TSource, TDestination>, object>(a.DestinationMember.Name));
コード例 #4
0
 public static IMappingExpression <TSource, TDest> IgnoreOther <TSource, TDest>(this IMappingExpression <TSource, TDest> expression)
 {
     expression.ForAllOtherMembers(opt => opt.Ignore());
     return(expression);
 }
コード例 #5
0
 /// <summary>
 /// Alternate syntax for ".ForAllOtherMembers(dest => dest.Ignore());
 /// Instead of:
 /// <![CDATA[
 ///     .ForAllOtherMembers(dest => dest.Ignore());
 /// ]]>
 /// ...you can code:
 /// <![CDATA[
 ///     .IgnoringAllOtherMembers()
 /// ]]>
 /// </summary>
 /// <typeparam name="TSource">Source ("map from") type.</typeparam>
 /// <typeparam name="TDestination">Destination ("map to") type.</typeparam>
 /// <param name="mappingExpression">
 /// AutoMapper <see cref="IMappingExpression{TSource, TDestination}"/> instance.
 /// </param>
 public static void IgnoreAllOtherMembers <TSource, TDestination>(
     this IMappingExpression <TSource, TDestination> mappingExpression)
 {
     mappingExpression.ForAllOtherMembers(dest => dest.Ignore());
 }
コード例 #6
0
 public static void IgnoreAllOtherMembers(this IMappingExpression map) =>
 map.ForAllOtherMembers(o => o.Ignore());
コード例 #7
0
 public static void IgnoreAllOtherMembers <TSource, TDestination>(
     this IMappingExpression <TSource, TDestination> map) =>
 map.ForAllOtherMembers(o => o.Ignore());
コード例 #8
0
        public static IMappingExpression <TSource, TDest> IgnoreOther <TSource, TDest>(this IMappingExpression <TSource, TDest> mapperExpression)
        {
            mapperExpression.ForAllOtherMembers(u => u.Ignore());

            return(mapperExpression);
        }