Skip to content

Commit

Permalink
Merge pull request #4388 from AutoMapper/revert-nullables
Browse files Browse the repository at this point in the history
Revert "nullable annotations for the runtime public API"
  • Loading branch information
jbogard committed Feb 7, 2024
2 parents df315ec + 66e4498 commit f137534
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/AutoMapper/Configuration/MapperConfigurationExpression.cs
Expand Up @@ -177,7 +177,7 @@ private void AddMapsCore(IEnumerable<Assembly> assembliesToScan)
{
foreach (var memberConfigurationProvider in memberInfo.GetCustomAttributes().OfType<IMemberConfigurationProvider>())
{
mappingExpression.ForMember(memberInfo, memberConfigurationProvider.ApplyConfiguration);
mappingExpression.ForMember(memberInfo, cfg => memberConfigurationProvider.ApplyConfiguration(cfg));
}
}

Expand All @@ -188,5 +188,5 @@ private void AddMapsCore(IEnumerable<Assembly> assembliesToScan)
AddProfile(autoMapAttributeProfile);
}

public void ConstructServicesUsing(Func<Type, object> constructor) => _serviceCtor = constructor ?? throw new ArgumentNullException(nameof(constructor));
public void ConstructServicesUsing(Func<Type, object> constructor) => _serviceCtor = constructor;
}
29 changes: 14 additions & 15 deletions src/AutoMapper/Mapper.cs
@@ -1,7 +1,7 @@
namespace AutoMapper;

using IObjectMappingOperationOptions = IMappingOperationOptions<object, object>;
using Factory = Func<Type, object>;
#nullable enable
public interface IMapperBase
{
/// <summary>
Expand All @@ -11,15 +11,15 @@ public interface IMapperBase
/// <typeparam name="TDestination">Destination type to create</typeparam>
/// <param name="source">Source object to map from</param>
/// <returns>Mapped destination object</returns>
TDestination? Map<TDestination>(object? source);
TDestination Map<TDestination>(object source);
/// <summary>
/// Execute a mapping from the source object to a new destination object.
/// </summary>
/// <typeparam name="TSource">Source type to use</typeparam>
/// <typeparam name="TDestination">Destination type to create</typeparam>
/// <param name="source">Source object to map from</param>
/// <returns>Mapped destination object</returns>
TDestination? Map<TSource, TDestination>(TSource? source);
TDestination Map<TSource, TDestination>(TSource source);
/// <summary>
/// Execute a mapping from the source object to the existing destination object.
/// </summary>
Expand All @@ -28,15 +28,15 @@ public interface IMapperBase
/// <param name="source">Source object to map from</param>
/// <param name="destination">Destination object to map into</param>
/// <returns>The mapped destination object</returns>
TDestination? Map<TSource, TDestination>(TSource? source, TDestination? destination);
TDestination Map<TSource, TDestination>(TSource source, TDestination destination);
/// <summary>
/// Execute a mapping from the source object to a new destination object with explicit <see cref="System.Type"/> objects
/// </summary>
/// <param name="source">Source object to map from</param>
/// <param name="sourceType">Source type to use</param>
/// <param name="destinationType">Destination type to create</param>
/// <returns>Mapped destination object</returns>
object? Map(object? source, Type? sourceType, Type destinationType);
object Map(object source, Type sourceType, Type destinationType);
/// <summary>
/// Execute a mapping from the source object to existing destination object with explicit <see cref="System.Type"/> objects
/// </summary>
Expand All @@ -45,7 +45,7 @@ public interface IMapperBase
/// <param name="sourceType">Source type to use</param>
/// <param name="destinationType">Destination type to use</param>
/// <returns>Mapped destination object</returns>
object? Map(object? source, object? destination, Type? sourceType, Type? destinationType);
object Map(object source, object destination, Type sourceType, Type destinationType);
}
public interface IMapper : IMapperBase
{
Expand All @@ -56,7 +56,7 @@ public interface IMapper : IMapperBase
/// <param name="source">Source object to map from</param>
/// <param name="opts">Mapping options</param>
/// <returns>Mapped destination object</returns>
TDestination? Map<TDestination>(object? source, Action<IMappingOperationOptions<object, TDestination>> opts);
TDestination Map<TDestination>(object source, Action<IMappingOperationOptions<object, TDestination>> opts);
/// <summary>
/// Execute a mapping from the source object to a new destination object with supplied mapping options.
/// </summary>
Expand All @@ -65,7 +65,7 @@ public interface IMapper : IMapperBase
/// <param name="source">Source object to map from</param>
/// <param name="opts">Mapping options</param>
/// <returns>Mapped destination object</returns>
TDestination? Map<TSource, TDestination>(TSource? source, Action<IMappingOperationOptions<TSource, TDestination>> opts);
TDestination Map<TSource, TDestination>(TSource source, Action<IMappingOperationOptions<TSource, TDestination>> opts);
/// <summary>
/// Execute a mapping from the source object to the existing destination object with supplied mapping options.
/// </summary>
Expand All @@ -75,7 +75,7 @@ public interface IMapper : IMapperBase
/// <param name="destination">Destination object to map into</param>
/// <param name="opts">Mapping options</param>
/// <returns>The mapped destination object</returns>
TDestination? Map<TSource, TDestination>(TSource? source, TDestination? destination, Action<IMappingOperationOptions<TSource, TDestination>> opts);
TDestination Map<TSource, TDestination>(TSource source, TDestination destination, Action<IMappingOperationOptions<TSource, TDestination>> opts);
/// <summary>
/// Execute a mapping from the source object to a new destination object with explicit <see cref="System.Type"/> objects and supplied mapping options.
/// </summary>
Expand All @@ -84,7 +84,7 @@ public interface IMapper : IMapperBase
/// <param name="destinationType">Destination type to create</param>
/// <param name="opts">Mapping options</param>
/// <returns>Mapped destination object</returns>
object? Map(object? source, Type? sourceType, Type destinationType, Action<IObjectMappingOperationOptions> opts);
object Map(object source, Type sourceType, Type destinationType, Action<IObjectMappingOperationOptions> opts);
/// <summary>
/// Execute a mapping from the source object to existing destination object with supplied mapping options and explicit <see cref="System.Type"/> objects
/// </summary>
Expand All @@ -94,7 +94,7 @@ public interface IMapper : IMapperBase
/// <param name="destinationType">Destination type to use</param>
/// <param name="opts">Mapping options</param>
/// <returns>Mapped destination object</returns>
object? Map(object? source, object? destination, Type? sourceType, Type? destinationType, Action<IObjectMappingOperationOptions> opts);
object Map(object source, object destination, Type sourceType, Type destinationType, Action<IObjectMappingOperationOptions> opts);
/// <summary>
/// Configuration provider for performing maps
/// </summary>
Expand All @@ -108,7 +108,7 @@ public interface IMapper : IMapperBase
/// <param name="parameters">Optional parameter object for parameterized mapping expressions</param>
/// <param name="membersToExpand">Explicit members to expand</param>
/// <returns>Queryable result, use queryable extension methods to project and execute result</returns>
IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, object? parameters = null, params Expression<Func<TDestination, object>>[] membersToExpand);
IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, object parameters = null, params Expression<Func<TDestination, object>>[] membersToExpand);
/// <summary>
/// Project the input queryable.
/// </summary>
Expand All @@ -117,7 +117,7 @@ public interface IMapper : IMapperBase
/// <param name="parameters">Optional parameter object for parameterized mapping expressions</param>
/// <param name="membersToExpand">Explicit members to expand</param>
/// <returns>Queryable result, use queryable extension methods to project and execute result</returns>
IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, IDictionary<string, object>? parameters, params string[] membersToExpand);
IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, IDictionary<string, object> parameters, params string[] membersToExpand);
/// <summary>
/// Project the input queryable.
/// </summary>
Expand All @@ -126,12 +126,11 @@ public interface IMapper : IMapperBase
/// <param name="parameters">Optional parameter object for parameterized mapping expressions</param>
/// <param name="membersToExpand">Explicit members to expand</param>
/// <returns>Queryable result, use queryable extension methods to project and execute result</returns>
IQueryable ProjectTo(IQueryable source, Type destinationType, IDictionary<string, object>? parameters = null, params string[] membersToExpand);
IQueryable ProjectTo(IQueryable source, Type destinationType, IDictionary<string, object> parameters = null, params string[] membersToExpand);
}
public interface IRuntimeMapper : IMapperBase
{
}
#nullable disable
internal interface IInternalRuntimeMapper : IRuntimeMapper
{
TDestination Map<TSource, TDestination>(TSource source, TDestination destination, ResolutionContext context, Type sourceType = null, Type destinationType = null, MemberMap memberMap = null);
Expand Down
9 changes: 4 additions & 5 deletions src/AutoMapper/QueryableExtensions/Extensions.cs
@@ -1,4 +1,5 @@
namespace AutoMapper.QueryableExtensions;

using MemberPaths = IEnumerable<MemberInfo[]>;
using ParameterBag = IDictionary<string, object>;
/// <summary>
Expand All @@ -19,8 +20,7 @@ public static class Extensions
/// <param name="parameters">Optional parameter object for parameterized mapping expressions</param>
/// <param name="membersToExpand">Explicit members to expand</param>
/// <returns>Expression to project into</returns>
#nullable enable
public static IQueryable<TDestination> ProjectTo<TDestination>(this IQueryable source, IConfigurationProvider configuration, object? parameters, params Expression<Func<TDestination, object>>[] membersToExpand) =>
public static IQueryable<TDestination> ProjectTo<TDestination>(this IQueryable source, IConfigurationProvider configuration, object parameters, params Expression<Func<TDestination, object>>[] membersToExpand) =>
source.ToCore<TDestination>(configuration, parameters, membersToExpand.Select(MemberVisitor.GetMemberPath));
/// <summary>
/// Extension method to project from a queryable using the provided mapping engine
Expand All @@ -43,7 +43,7 @@ public static class Extensions
/// <param name="parameters">Optional parameter object for parameterized mapping expressions</param>
/// <param name="membersToExpand">Explicit members to expand</param>
/// <returns>Queryable result, use queryable extension methods to project and execute result</returns>
public static IQueryable<TDestination> ProjectTo<TDestination>(this IQueryable source, IConfigurationProvider configuration, ParameterBag? parameters, params string[] membersToExpand) =>
public static IQueryable<TDestination> ProjectTo<TDestination>(this IQueryable source, IConfigurationProvider configuration, ParameterBag parameters, params string[] membersToExpand) =>
source.ToCore<TDestination>(configuration, parameters, membersToExpand.Select(memberName => ReflectionHelper.GetMemberPath(typeof(TDestination), memberName)));
/// <summary>
/// Extension method to project from a queryable using the provided mapping engine
Expand All @@ -64,9 +64,8 @@ public static class Extensions
/// <param name="parameters">Optional parameter object for parameterized mapping expressions</param>
/// <param name="membersToExpand">Explicit members to expand</param>
/// <returns>Queryable result, use queryable extension methods to project and execute result</returns>
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<TResult> ToCore<TResult>(this IQueryable source, IConfigurationProvider configuration, object parameters, MemberPaths memberPathsToExpand) =>
(IQueryable<TResult>)source.ToCore(typeof(TResult), configuration, parameters, memberPathsToExpand);
static IQueryable ToCore(this IQueryable source, Type destinationType, IConfigurationProvider configuration, object parameters, MemberPaths memberPathsToExpand) =>
Expand Down

0 comments on commit f137534

Please sign in to comment.