diff --git a/src/AutoMapper/Configuration/MapperConfigurationExpression.cs b/src/AutoMapper/Configuration/MapperConfigurationExpression.cs index 6c7ad6f177..e4998d49da 100644 --- a/src/AutoMapper/Configuration/MapperConfigurationExpression.cs +++ b/src/AutoMapper/Configuration/MapperConfigurationExpression.cs @@ -177,7 +177,7 @@ private void AddMapsCore(IEnumerable assembliesToScan) { foreach (var memberConfigurationProvider in memberInfo.GetCustomAttributes().OfType()) { - mappingExpression.ForMember(memberInfo, memberConfigurationProvider.ApplyConfiguration); + mappingExpression.ForMember(memberInfo, cfg => memberConfigurationProvider.ApplyConfiguration(cfg)); } } @@ -188,5 +188,5 @@ private void AddMapsCore(IEnumerable assembliesToScan) AddProfile(autoMapAttributeProfile); } - public void ConstructServicesUsing(Func constructor) => _serviceCtor = constructor ?? throw new ArgumentNullException(nameof(constructor)); + public void ConstructServicesUsing(Func constructor) => _serviceCtor = constructor; } \ No newline at end of file diff --git a/src/AutoMapper/Mapper.cs b/src/AutoMapper/Mapper.cs index 4f82f2169d..2e3c42f997 100644 --- a/src/AutoMapper/Mapper.cs +++ b/src/AutoMapper/Mapper.cs @@ -1,7 +1,7 @@ namespace AutoMapper; + using IObjectMappingOperationOptions = IMappingOperationOptions; using Factory = Func; -#nullable enable public interface IMapperBase { /// @@ -11,7 +11,7 @@ public interface IMapperBase /// Destination type to create /// Source object to map from /// Mapped destination object - TDestination? Map(object? source); + TDestination Map(object source); /// /// Execute a mapping from the source object to a new destination object. /// @@ -19,7 +19,7 @@ public interface IMapperBase /// Destination type to create /// Source object to map from /// Mapped destination object - TDestination? Map(TSource? source); + TDestination Map(TSource source); /// /// Execute a mapping from the source object to the existing destination object. /// @@ -28,7 +28,7 @@ public interface IMapperBase /// Source object to map from /// Destination object to map into /// The mapped destination object - TDestination? Map(TSource? source, TDestination? destination); + TDestination Map(TSource source, TDestination destination); /// /// Execute a mapping from the source object to a new destination object with explicit objects /// @@ -36,7 +36,7 @@ public interface IMapperBase /// Source type to use /// Destination type to create /// Mapped destination object - object? Map(object? source, Type? sourceType, Type destinationType); + object Map(object source, Type sourceType, Type destinationType); /// /// Execute a mapping from the source object to existing destination object with explicit objects /// @@ -45,7 +45,7 @@ public interface IMapperBase /// Source type to use /// Destination type to use /// Mapped destination object - object? Map(object? source, object? destination, Type? sourceType, Type? destinationType); + object Map(object source, object destination, Type sourceType, Type destinationType); } public interface IMapper : IMapperBase { @@ -56,7 +56,7 @@ public interface IMapper : IMapperBase /// Source object to map from /// Mapping options /// Mapped destination object - TDestination? Map(object? source, Action> opts); + TDestination Map(object source, Action> opts); /// /// Execute a mapping from the source object to a new destination object with supplied mapping options. /// @@ -65,7 +65,7 @@ public interface IMapper : IMapperBase /// Source object to map from /// Mapping options /// Mapped destination object - TDestination? Map(TSource? source, Action> opts); + TDestination Map(TSource source, Action> opts); /// /// Execute a mapping from the source object to the existing destination object with supplied mapping options. /// @@ -75,7 +75,7 @@ public interface IMapper : IMapperBase /// Destination object to map into /// Mapping options /// The mapped destination object - TDestination? Map(TSource? source, TDestination? destination, Action> opts); + TDestination Map(TSource source, TDestination destination, Action> opts); /// /// Execute a mapping from the source object to a new destination object with explicit objects and supplied mapping options. /// @@ -84,7 +84,7 @@ public interface IMapper : IMapperBase /// Destination type to create /// Mapping options /// Mapped destination object - object? Map(object? source, Type? sourceType, Type destinationType, Action opts); + object Map(object source, Type sourceType, Type destinationType, Action opts); /// /// Execute a mapping from the source object to existing destination object with supplied mapping options and explicit objects /// @@ -94,7 +94,7 @@ public interface IMapper : IMapperBase /// Destination type to use /// Mapping options /// Mapped destination object - object? Map(object? source, object? destination, Type? sourceType, Type? destinationType, Action opts); + object Map(object source, object destination, Type sourceType, Type destinationType, Action opts); /// /// Configuration provider for performing maps /// @@ -108,7 +108,7 @@ public interface IMapper : IMapperBase /// Optional parameter object for parameterized mapping expressions /// Explicit members to expand /// Queryable result, use queryable extension methods to project and execute result - IQueryable ProjectTo(IQueryable source, object? parameters = null, params Expression>[] membersToExpand); + IQueryable ProjectTo(IQueryable source, object parameters = null, params Expression>[] membersToExpand); /// /// Project the input queryable. /// @@ -117,7 +117,7 @@ public interface IMapper : IMapperBase /// Optional parameter object for parameterized mapping expressions /// Explicit members to expand /// Queryable result, use queryable extension methods to project and execute result - IQueryable ProjectTo(IQueryable source, IDictionary? parameters, params string[] membersToExpand); + IQueryable ProjectTo(IQueryable source, IDictionary parameters, params string[] membersToExpand); /// /// Project the input queryable. /// @@ -126,12 +126,11 @@ public interface IMapper : IMapperBase /// Optional parameter object for parameterized mapping expressions /// Explicit members to expand /// Queryable result, use queryable extension methods to project and execute result - IQueryable ProjectTo(IQueryable source, Type destinationType, IDictionary? parameters = null, params string[] membersToExpand); + IQueryable ProjectTo(IQueryable source, Type destinationType, IDictionary parameters = null, params string[] membersToExpand); } public interface IRuntimeMapper : IMapperBase { } -#nullable disable internal interface IInternalRuntimeMapper : IRuntimeMapper { TDestination Map(TSource source, TDestination destination, ResolutionContext context, Type sourceType = null, Type destinationType = null, MemberMap memberMap = null); diff --git a/src/AutoMapper/QueryableExtensions/Extensions.cs b/src/AutoMapper/QueryableExtensions/Extensions.cs index 5bad8cd9fc..6ecb99e1fa 100644 --- a/src/AutoMapper/QueryableExtensions/Extensions.cs +++ b/src/AutoMapper/QueryableExtensions/Extensions.cs @@ -1,4 +1,5 @@ namespace AutoMapper.QueryableExtensions; + using MemberPaths = IEnumerable; using ParameterBag = IDictionary; /// @@ -19,8 +20,7 @@ public static class Extensions /// Optional parameter object for parameterized mapping expressions /// Explicit members to expand /// Expression to project into -#nullable enable - public static IQueryable ProjectTo(this IQueryable source, IConfigurationProvider configuration, object? parameters, params Expression>[] membersToExpand) => + public static IQueryable ProjectTo(this IQueryable source, IConfigurationProvider configuration, object parameters, params Expression>[] membersToExpand) => source.ToCore(configuration, parameters, membersToExpand.Select(MemberVisitor.GetMemberPath)); /// /// Extension method to project from a queryable using the provided mapping engine @@ -43,7 +43,7 @@ public static class Extensions /// Optional parameter object for parameterized mapping expressions /// Explicit members to expand /// Queryable result, use queryable extension methods to project and execute result - public static IQueryable ProjectTo(this IQueryable source, IConfigurationProvider configuration, ParameterBag? parameters, params string[] membersToExpand) => + public static IQueryable ProjectTo(this IQueryable source, IConfigurationProvider configuration, ParameterBag parameters, params string[] membersToExpand) => source.ToCore(configuration, parameters, membersToExpand.Select(memberName => ReflectionHelper.GetMemberPath(typeof(TDestination), memberName))); /// /// Extension method to project from a queryable using the provided mapping engine @@ -64,9 +64,8 @@ public static class Extensions /// Optional parameter object for parameterized mapping expressions /// Explicit members to expand /// Queryable result, use queryable extension methods to project and execute result - public static IQueryable ProjectTo(this IQueryable source, Type destinationType, IConfigurationProvider configuration, ParameterBag? parameters, params string[] membersToExpand) => + public static IQueryable ProjectTo(this IQueryable source, Type destinationType, IConfigurationProvider configuration, ParameterBag parameters, params string[] membersToExpand) => source.ToCore(destinationType, configuration, parameters, membersToExpand.Select(memberName => ReflectionHelper.GetMemberPath(destinationType, memberName))); -#nullable disable static IQueryable ToCore(this IQueryable source, IConfigurationProvider configuration, object parameters, MemberPaths memberPathsToExpand) => (IQueryable)source.ToCore(typeof(TResult), configuration, parameters, memberPathsToExpand); static IQueryable ToCore(this IQueryable source, Type destinationType, IConfigurationProvider configuration, object parameters, MemberPaths memberPathsToExpand) =>