Skip to content

Commit 10150bb

Browse files
authored
Merge pull request #4474 from AutoMapper/seal_mappers
Target .net 8 and seal more classes
2 parents 2314ed6 + 3bf94bd commit 10150bb

32 files changed

+103
-48
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
run: ./Push.ps1
3636
shell: pwsh
3737
- name: Artifacts
38-
uses: actions/upload-artifact@v2
38+
uses: actions/upload-artifact@v4
3939
with:
4040
name: artifacts
4141
path: artifacts/**/*

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
run: ./Push.ps1
3737
shell: pwsh
3838
- name: Artifacts
39-
uses: actions/upload-artifact@v2
39+
uses: actions/upload-artifact@v4
4040
with:
4141
name: artifacts
4242
path: artifacts/**/*

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ If you're still running into problems, file an issue above.
6969
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
7070
For more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
7171

72-
AutoMapper is Copyright © 2009 [Jimmy Bogard](https://jimmybogard.com) and other contributors under the [MIT license](LICENSE.txt).
72+
AutoMapper is Copyright © 2009 [Jimmy Bogard](https://jimmybogard.com) and other contributors under the [MIT license](https://github.com/AutoMapper/AutoMapper?tab=MIT-1-ov-file#MIT-1-ov-file).
7373

7474
### .NET Foundation
7575

src/AutoMapper/ApiCompatBaseline.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,25 @@ CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMappe
3939
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.UseExistingValueAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
4040
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.ValueConverterAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
4141
CannotChangeAttribute : Attribute 'System.AttributeUsageAttribute' on 'AutoMapper.Configuration.Annotations.ValueResolverAttribute' changed from '[AttributeUsageAttribute(384)]' in the contract to '[AttributeUsageAttribute(AttributeTargets.Field | AttributeTargets.Property)]' in the implementation.
42+
CannotSealType : Type 'AutoMapper.Internal.Mappers.AssignableMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
43+
CannotSealType : Type 'AutoMapper.Internal.Mappers.CollectionMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
44+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ConstructorMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
45+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ConversionOperatorMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
46+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ConvertMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
47+
CannotSealType : Type 'AutoMapper.Internal.Mappers.EnumToEnumMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
48+
CannotSealType : Type 'AutoMapper.Internal.Mappers.FromDynamicMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
49+
CannotSealType : Type 'AutoMapper.Internal.Mappers.FromStringDictionaryMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
50+
CannotSealType : Type 'AutoMapper.Internal.Mappers.KeyValueMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
4251
CannotSealType : Type 'AutoMapper.Internal.Mappers.MultidimensionalArrayFiller' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
4352
TypeCannotChangeClassification : Type 'AutoMapper.Internal.Mappers.MultidimensionalArrayFiller' is a 'struct' in the implementation but is a 'class' in the contract.
53+
CannotSealType : Type 'AutoMapper.Internal.Mappers.NullableDestinationMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
54+
CannotSealType : Type 'AutoMapper.Internal.Mappers.NullableSourceMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
55+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ParseStringMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
56+
CannotSealType : Type 'AutoMapper.Internal.Mappers.StringToEnumMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
57+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ToDynamicMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
58+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ToStringDictionaryMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
59+
CannotSealType : Type 'AutoMapper.Internal.Mappers.ToStringMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
60+
CannotSealType : Type 'AutoMapper.Internal.Mappers.UnderlyingTypeEnumMapper' is actually (has the sealed modifier) sealed in the implementation but not sealed in the contract.
4461
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableContextAttribute' exists on 'AutoMapper.QueryableExtensions.Extensions.ProjectTo(System.Linq.IQueryable, System.Type, AutoMapper.IConfigurationProvider)' in the contract but not the implementation.
4562
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableContextAttribute' exists on 'AutoMapper.QueryableExtensions.Extensions.ProjectTo(System.Linq.IQueryable, System.Type, AutoMapper.IConfigurationProvider, System.Collections.Generic.IDictionary<System.String, System.Object>, System.String[])' in the contract but not the implementation.
4663
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableAttribute' exists on parameter 'parameters' on member 'AutoMapper.QueryableExtensions.Extensions.ProjectTo(System.Linq.IQueryable, System.Type, AutoMapper.IConfigurationProvider, System.Collections.Generic.IDictionary<System.String, System.Object>, System.String[])' in the contract but not the implementation.
@@ -52,4 +69,4 @@ CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableAttri
5269
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableContextAttribute' exists on 'AutoMapper.QueryableExtensions.Extensions.ProjectTo<TDestination>(System.Linq.IQueryable, AutoMapper.IConfigurationProvider, System.Object, System.Linq.Expressions.Expression<System.Func<TDestination, System.Object>>[])' in the contract but not the implementation.
5370
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableAttribute' exists on parameter 'parameters' on member 'AutoMapper.QueryableExtensions.Extensions.ProjectTo<TDestination>(System.Linq.IQueryable, AutoMapper.IConfigurationProvider, System.Object, System.Linq.Expressions.Expression<System.Func<TDestination, System.Object>>[])' in the contract but not the implementation.
5471
CannotRemoveAttribute : Attribute 'System.Runtime.CompilerServices.NullableAttribute' exists on generic param 'TDestination' on member 'AutoMapper.QueryableExtensions.Extensions.ProjectTo<TDestination>(System.Linq.IQueryable, AutoMapper.IConfigurationProvider, System.Object, System.Linq.Expressions.Expression<System.Func<TDestination, System.Object>>[])' in the contract but not the implementation.
55-
Total Issues: 53
72+
Total Issues: 70

src/AutoMapper/AutoMapper.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Summary>A convention-based object-object mapper.</Summary>
55
<Description>A convention-based object-object mapper.</Description>
6-
<TargetFrameworks>net6.0</TargetFrameworks>
6+
<TargetFrameworks>net8.0</TargetFrameworks>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<AssemblyName>AutoMapper</AssemblyName>
99
<AssemblyOriginatorKeyFile>..\..\AutoMapper.snk</AssemblyOriginatorKeyFile>
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
41+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
4242
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All" />
4343
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
4444
<PackageReference Include="Microsoft.DotNet.ApiCompat" Version="7.0.0-beta.22074.1" PrivateAssets="All" />

src/AutoMapper/ConstructorMap.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ public bool ApplyMap(TypeMap typeMap, IncludedMember includedMember = null)
6767
[EditorBrowsable(EditorBrowsableState.Never)]
6868
public class ConstructorParameterMap : MemberMap
6969
{
70-
public ConstructorParameterMap(TypeMap typeMap, ParameterInfo parameter, MemberInfo[] sourceMembers) : base(typeMap)
70+
public ConstructorParameterMap(TypeMap typeMap, ParameterInfo parameter, MemberInfo[] sourceMembers) : base(typeMap, parameter.ParameterType)
7171
{
7272
Parameter = parameter;
73+
if(DestinationType.IsByRef)
74+
{
75+
DestinationType = DestinationType.GetElementType();
76+
}
7377
if (sourceMembers.Length > 0)
7478
{
7579
MapByConvention(sourceMembers);
@@ -80,7 +84,6 @@ public ConstructorParameterMap(TypeMap typeMap, ParameterInfo parameter, MemberI
8084
}
8185
}
8286
public ParameterInfo Parameter { get; }
83-
public override Type DestinationType => Parameter.ParameterType;
8487
public override IncludedMember IncludedMember { get; protected set; }
8588
public override MemberInfo[] SourceMembers { get; set; }
8689
public override string DestinationName => Parameter.Name;

src/AutoMapper/Mappers/AssignableMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace AutoMapper.Internal.Mappers;
22

3-
public class AssignableMapper : IObjectMapper
3+
public sealed class AssignableMapper : IObjectMapper
44
{
55
public bool IsMatch(TypePair context) => context.DestinationType.IsAssignableFrom(context.SourceType);
66
public Expression MapExpression(IGlobalConfiguration configuration, ProfileMap profileMap,

src/AutoMapper/Mappers/CollectionMapper.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.Specialized;
44
namespace AutoMapper.Internal.Mappers;
55
using static ReflectionHelper;
6-
public class CollectionMapper : IObjectMapper
6+
public sealed class CollectionMapper : IObjectMapper
77
{
88
static readonly MethodInfo IListAdd = typeof(IList).GetMethod(nameof(IList.Add));
99
public TypePair? GetAssociatedTypes(TypePair context) => new(GetElementType(context.SourceType), GetElementType(context.DestinationType));
@@ -241,24 +241,23 @@ bool MustMap(Type sourceType, Type destinationType) => !destinationType.IsAssign
241241
}
242242
public readonly struct MultidimensionalArrayFiller(Array destination)
243243
{
244-
private readonly int[] _indices = new int[destination.Rank];
245-
private readonly Array _destination = destination;
244+
readonly int[] _indices = new int[destination.Rank];
246245
public void NewValue(object value)
247246
{
248-
var dimension = _destination.Rank - 1;
247+
var dimension = destination.Rank - 1;
249248
var changedDimension = false;
250-
while (_indices[dimension] == _destination.GetLength(dimension))
249+
while (_indices[dimension] == destination.GetLength(dimension))
251250
{
252251
_indices[dimension] = 0;
253252
dimension--;
254253
if (dimension < 0)
255254
{
256-
throw new InvalidOperationException("Not enough room in destination array " + _destination);
255+
throw new InvalidOperationException("Not enough room in destination array " + destination);
257256
}
258257
_indices[dimension]++;
259258
changedDimension = true;
260259
}
261-
_destination.SetValue(value, _indices);
260+
destination.SetValue(value, _indices);
262261
if (changedDimension)
263262
{
264263
_indices[dimension + 1]++;

src/AutoMapper/Mappers/ConstructorMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace AutoMapper.Internal.Mappers;
2-
public class ConstructorMapper : IObjectMapper
2+
public sealed class ConstructorMapper : IObjectMapper
33
{
44
public bool IsMatch(TypePair context) => GetConstructor(context.SourceType, context.DestinationType) != null;
55
private static ConstructorInfo GetConstructor(Type sourceType, Type destinationType) =>

src/AutoMapper/Mappers/ConversionOperatorMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
namespace AutoMapper.Internal.Mappers;
2-
public class ConversionOperatorMapper : IObjectMapper
2+
public sealed class ConversionOperatorMapper : IObjectMapper
33
{
44
private readonly string _operatorName;
55
public ConversionOperatorMapper(string operatorName) => _operatorName = operatorName;

0 commit comments

Comments
 (0)