public static void AddCollectionMappers(this IMapperConfigurationExpression cfg)
        {
            var mapper = new ObjectToEquivalencyExpressionByEquivalencyExistingMapper();

            cfg.Internal().Features.Set(new GeneratePropertyMapsExpressionFeature(mapper));
            cfg.Internal().InsertBefore <CollectionMapper>(
                mapper,
                new EquivalentExpressionAddRemoveCollectionMapper());
        }
Beispiel #2
0
        private static void applyCommonConfiguration(IMapperConfigurationExpression c)
        {
            c.ShouldMapField = fi => false;

            // This is specifically to avoid mapping explicit interface implementations.
            // If we want to limit this further, we can avoid mapping properties with no setter that are not IList<>.
            // Takes a bit of effort to determine whether this is the case though, see https://stackoverflow.com/questions/951536/how-do-i-tell-whether-a-type-implements-ilist
            c.ShouldMapProperty = pi => pi.GetMethod?.IsPublic == true;

            c.Internal().ForAllMaps((typeMap, expression) =>
            {
                expression.ForAllMembers(m =>
                {
                    if (m.DestinationMember.Has <IgnoredAttribute>() || m.DestinationMember.Has <BacklinkAttribute>() || m.DestinationMember.Has <IgnoreDataMemberAttribute>())
                    {
                        m.Ignore();
                    }
                });
            });

            c.CreateMap <RealmKeyBinding, RealmKeyBinding>();
            c.CreateMap <BeatmapMetadata, BeatmapMetadata>();
            c.CreateMap <BeatmapUserSettings, BeatmapUserSettings>();
            c.CreateMap <BeatmapDifficulty, BeatmapDifficulty>();
            c.CreateMap <RulesetInfo, RulesetInfo>();
            c.CreateMap <ScoreInfo, ScoreInfo>();
            c.CreateMap <RealmUser, RealmUser>();
            c.CreateMap <RealmFile, RealmFile>();
            c.CreateMap <RealmNamedFileUsage, RealmNamedFileUsage>();
        }
 public static void SetGeneratePropertyMaps <TGeneratePropertyMaps>(this IMapperConfigurationExpression cfg)
     where TGeneratePropertyMaps : IGeneratePropertyMaps
 {
     (cfg.Internal().Features.Get <GeneratePropertyMapsExpressionFeature>()
      ?? throw new ArgumentException("Invoke the IMapperConfigurationExpression.AddCollectionMappers() before adding IGeneratePropertyMaps."))
     .Add(serviceCtor => (IGeneratePropertyMaps)serviceCtor(typeof(TGeneratePropertyMaps)));
 }
Beispiel #4
0
 public static IMapperConfigurationExpression SetFeature(
     this IMapperConfigurationExpression configuration,
     IGlobalFeature feature
     )
 {
     configuration.Internal().Features.Set(feature);
     return(configuration);
 }
 /// <summary>
 /// Enable EnumMapping configuration validation
 /// </summary>
 /// <param name="mapperConfigurationExpression">Configuration object for AutoMapper</param>
 public static void EnableEnumMappingValidation(this IMapperConfigurationExpression mapperConfigurationExpression)
 {
     mapperConfigurationExpression.Internal().Validator(context =>
     {
         if (context.TypeMap != null)
         {
             var validator = context.TypeMap.Features.OfType <IEnumMappingValidationRuntimeFeature>().SingleOrDefault();
             validator?.Validate(context.TypeMap.Types);
         }
     });
 }
        private static void InsertBefore <TObjectMapper>(this IMapperConfigurationExpression cfg, params IObjectMapper[] adds)
            where TObjectMapper : IObjectMapper
        {
            var mappers      = cfg.Internal().Mappers;
            var targetMapper = mappers.FirstOrDefault(om => om is TObjectMapper);
            var index        = targetMapper == null ? 0 : mappers.IndexOf(targetMapper);

            foreach (var mapper in adds.Reverse())
            {
                mappers.Insert(index, mapper);
            }
        }
Beispiel #7
0
 public static void ForAllPropertyMaps(this IMapperConfigurationExpression configurationProvider, Func <PropertyMap, bool> condition, Action <PropertyMap, IMemberConfigurationExpression> memberOptions) =>
 configurationProvider.Internal().ForAllPropertyMaps(condition, memberOptions);
Beispiel #8
0
 public static void ForAllMaps(this IMapperConfigurationExpression configurationProvider, Action <TypeMap, IMappingExpression> configuration) => configurationProvider.Internal().ForAllMaps(configuration);
 public static void SetGeneratePropertyMaps(this IMapperConfigurationExpression cfg, IGeneratePropertyMaps generatePropertyMaps)
 {
     (cfg.Internal().Features.Get <GeneratePropertyMapsExpressionFeature>()
      ?? throw new ArgumentException("Invoke the IMapperConfigurationExpression.AddCollectionMappers() before adding IGeneratePropertyMaps."))
     .Add(_ => generatePropertyMaps);
 }
Beispiel #10
0
 public static IMapperConfigurationExpression AddExpressionMapping(this IMapperConfigurationExpression config)
 {
     config.Internal().Mappers.Insert(0, new ExpressionMapper());
     return(config);
 }