From c6e007ca38640db60516484e504e7b3cddc75ce6 Mon Sep 17 00:00:00 2001 From: Blaise Taylor Date: Sat, 12 Jul 2025 10:00:51 -0400 Subject: [PATCH] Supporting .NetStandard. --- ...Mapper.Extensions.ExpressionMapping.csproj | 4 ++-- ...ensions.ExpressionMapping.UnitTests.csproj | 5 ++-- .../CanMapExpressionWithListConstants.cs | 8 +++---- ...apExpressionWithLocalExpressionConstant.cs | 4 ++-- .../CanMapMemberFromTypeBinaryExpression.cs | 16 +++++++++++++ ...mberExpressionsWithoutCustomExpressions.cs | 24 +++++++++++++++++++ ...dOperationExceptionForUnmatchedLiterals.cs | 16 +++++++++++++ ...dUseDeclaringTypeForInstanceMethodCalls.cs | 8 +++---- 8 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/AutoMapper.Extensions.ExpressionMapping/AutoMapper.Extensions.ExpressionMapping.csproj b/src/AutoMapper.Extensions.ExpressionMapping/AutoMapper.Extensions.ExpressionMapping.csproj index fe59df1..ac8b6da 100644 --- a/src/AutoMapper.Extensions.ExpressionMapping/AutoMapper.Extensions.ExpressionMapping.csproj +++ b/src/AutoMapper.Extensions.ExpressionMapping/AutoMapper.Extensions.ExpressionMapping.csproj @@ -3,7 +3,7 @@ Expression mapping (OData) extensions for AutoMapper Expression mapping (OData) extensions for AutoMapper - net8.0 + netstandard2.0;net8.0;net9.0 true ..\..\AutoMapper.snk true @@ -29,7 +29,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/AutoMapper.Extensions.ExpressionMapping.UnitTests.csproj b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/AutoMapper.Extensions.ExpressionMapping.UnitTests.csproj index d055c17..a517d77 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/AutoMapper.Extensions.ExpressionMapping.UnitTests.csproj +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/AutoMapper.Extensions.ExpressionMapping.UnitTests.csproj @@ -1,14 +1,15 @@  - net8.0 + net8.0 + net481;net8.0 false - + diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs index 96f9c10..bfbc466 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithListConstants.cs @@ -169,8 +169,8 @@ public enum SimpleEnum public record Entity { - public int Id { get; init; } - public SimpleEnum SimpleEnum { get; init; } + public int Id { get; set; } + public SimpleEnum SimpleEnum { get; set; } } public enum SimpleEnumModel @@ -182,8 +182,8 @@ public enum SimpleEnumModel public record EntityModel { - public int Id { get; init; } - public SimpleEnumModel SimpleEnum { get; init; } + public int Id { get; set; } + public SimpleEnumModel SimpleEnum { get; set; } } } } diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithLocalExpressionConstant.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithLocalExpressionConstant.cs index 1451df4..0d95616 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithLocalExpressionConstant.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapExpressionWithLocalExpressionConstant.cs @@ -38,12 +38,12 @@ public void Map_expression_wchich_includes_local_constant() public record Entity { - public int Id { get; init; } + public int Id { get; set; } } public record EntityModel { - public int Id { get; init; } + public int Id { get; set; } } } } diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMemberFromTypeBinaryExpression.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMemberFromTypeBinaryExpression.cs index bd42d44..69ddf35 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMemberFromTypeBinaryExpression.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMemberFromTypeBinaryExpression.cs @@ -30,11 +30,19 @@ public void Can_map_using_type_binary_expression_to_test_the_parameter_expressio //assert Assert.Single(list); +#if NET8_0_OR_GREATER Assert.Equal ( "x => (Convert(IIF((x Is Triangle), Triangle, IIF((x Is Circle), Circle, Unknown)), Int32) == 2)", whereMapped.ToString() ); +#else + Assert.Equal + ( + "x => (Convert(IIF((x Is Triangle), Triangle, IIF((x Is Circle), Circle, Unknown))) == 2)", + whereMapped.ToString() + ); +#endif } [Fact] @@ -66,11 +74,19 @@ public void Can_map_using_type_binary_expression_to_test_a_member_expression() //assert Assert.Single(list); +#if NET8_0_OR_GREATER Assert.Equal ( "x => (Convert(IIF((x.Shape Is Triangle), Triangle, IIF((x.Shape Is Circle), Circle, Unknown)), Int32) == 2)", whereMapped.ToString() ); +#else + Assert.Equal + ( + "x => (Convert(IIF((x.Shape Is Triangle), Triangle, IIF((x.Shape Is Circle), Circle, Unknown))) == 2)", + whereMapped.ToString() + ); +#endif } [Fact] diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMismatchedLiteralMemberExpressionsWithoutCustomExpressions.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMismatchedLiteralMemberExpressionsWithoutCustomExpressions.cs index ecf7bbf..c8f6549 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMismatchedLiteralMemberExpressionsWithoutCustomExpressions.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/CanMapMismatchedLiteralMemberExpressionsWithoutCustomExpressions.cs @@ -12,10 +12,14 @@ public class CanMapMismatchedLiteralMemberExpressionsWithoutCustomExpressions [InlineData(nameof(ProductModel.DateTime), typeof(DateTime))] [InlineData(nameof(ProductModel.DateTimeOffset), typeof(DateTimeOffset))] [InlineData(nameof(ProductModel.Date), typeof(Date))] +#if NET8_0_OR_GREATER [InlineData(nameof(ProductModel.DateOnly), typeof(DateOnly))] +#endif [InlineData(nameof(ProductModel.TimeSpan), typeof(TimeSpan))] [InlineData(nameof(ProductModel.TimeOfDay), typeof(TimeOfDay))] +#if NET8_0_OR_GREATER [InlineData(nameof(ProductModel.TimeOnly), typeof(TimeOnly))] +#endif [InlineData(nameof(ProductModel.Guid), typeof(Guid))] [InlineData(nameof(ProductModel.Decimal), typeof(decimal))] [InlineData(nameof(ProductModel.Byte), typeof(byte))] @@ -59,10 +63,14 @@ public void CanMapNonNullableToNullableWithoutCustomExpression(string memberName [InlineData(nameof(Product.DateTime), typeof(DateTime?))] [InlineData(nameof(Product.DateTimeOffset), typeof(DateTimeOffset?))] [InlineData(nameof(Product.Date), typeof(Date?))] +#if NET8_0_OR_GREATER [InlineData(nameof(Product.DateOnly), typeof(DateOnly?))] +#endif [InlineData(nameof(Product.TimeSpan), typeof(TimeSpan?))] [InlineData(nameof(Product.TimeOfDay), typeof(TimeOfDay?))] +#if NET8_0_OR_GREATER [InlineData(nameof(Product.TimeOnly), typeof(TimeOnly?))] +#endif [InlineData(nameof(Product.Guid), typeof(Guid?))] [InlineData(nameof(Product.Decimal), typeof(decimal?))] [InlineData(nameof(Product.Byte), typeof(byte?))] @@ -106,10 +114,14 @@ public void CanMapNullableToNonNullableWithoutCustomExpression(string memberName [InlineData(nameof(ProductModel.DateTime), typeof(DateTime))] [InlineData(nameof(ProductModel.DateTimeOffset), typeof(DateTimeOffset))] [InlineData(nameof(ProductModel.Date), typeof(Date))] +#if NET8_0_OR_GREATER [InlineData(nameof(ProductModel.DateOnly), typeof(DateOnly))] +#endif [InlineData(nameof(ProductModel.TimeSpan), typeof(TimeSpan))] [InlineData(nameof(ProductModel.TimeOfDay), typeof(TimeOfDay))] +#if NET8_0_OR_GREATER [InlineData(nameof(ProductModel.TimeOnly), typeof(TimeOnly))] +#endif [InlineData(nameof(ProductModel.Guid), typeof(Guid))] [InlineData(nameof(ProductModel.Decimal), typeof(decimal))] [InlineData(nameof(ProductModel.Byte), typeof(byte))] @@ -153,10 +165,14 @@ public void CanMapNonNullableSelectorToNullableelectorWithoutCustomExpression(st [InlineData(nameof(Product.DateTime), typeof(DateTime?))] [InlineData(nameof(Product.DateTimeOffset), typeof(DateTimeOffset?))] [InlineData(nameof(Product.Date), typeof(Date?))] +#if NET8_0_OR_GREATER [InlineData(nameof(Product.DateOnly), typeof(DateOnly?))] +#endif [InlineData(nameof(Product.TimeSpan), typeof(TimeSpan?))] [InlineData(nameof(Product.TimeOfDay), typeof(TimeOfDay?))] +#if NET8_0_OR_GREATER [InlineData(nameof(Product.TimeOnly), typeof(TimeOnly?))] +#endif [InlineData(nameof(Product.Guid), typeof(Guid?))] [InlineData(nameof(Product.Decimal), typeof(decimal?))] [InlineData(nameof(Product.Byte), typeof(byte?))] @@ -222,10 +238,14 @@ class Product public DateTimeOffset? DateTimeOffset { get; set; } public DateTime? DateTime { get; set; } public Date? Date { get; set; } +#if NET8_0_OR_GREATER public DateOnly? DateOnly { get; set; } +#endif public TimeSpan? TimeSpan { get; set; } public TimeOfDay? TimeOfDay { get; set; } +#if NET8_0_OR_GREATER public TimeOnly? TimeOnly { get; set; } +#endif public Guid? Guid { get; set; } public decimal? Decimal { get; set; } public byte? Byte { get; set; } @@ -247,10 +267,14 @@ class ProductModel public DateTimeOffset DateTimeOffset { get; set; } public DateTime DateTime { get; set; } public Date Date { get; set; } +#if NET8_0_OR_GREATER public DateOnly DateOnly { get; set; } +#endif public TimeSpan TimeSpan { get; set; } public TimeOfDay TimeOfDay { get; set; } +#if NET8_0_OR_GREATER public TimeOnly TimeOnly { get; set; } +#endif public Guid Guid { get; set; } public decimal Decimal { get; set; } public byte Byte { get; set; } diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldThrowInvalidOperationExceptionForUnmatchedLiterals.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldThrowInvalidOperationExceptionForUnmatchedLiterals.cs index 6fb88f9..5d91e6d 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldThrowInvalidOperationExceptionForUnmatchedLiterals.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldThrowInvalidOperationExceptionForUnmatchedLiterals.cs @@ -12,10 +12,14 @@ public class ShouldThrowInvalidOperationExceptionForUnmatchedLiterals [InlineData(nameof(ProductModel.DateTime), typeof(DateTime?))] [InlineData(nameof(ProductModel.DateTimeOffset), typeof(DateTimeOffset?))] [InlineData(nameof(ProductModel.Date), typeof(Date?))] +#if NET8_0_OR_GREATER [InlineData(nameof(ProductModel.DateOnly), typeof(DateOnly?))] +#endif [InlineData(nameof(ProductModel.TimeSpan), typeof(TimeSpan?))] [InlineData(nameof(ProductModel.TimeOfDay), typeof(TimeOfDay?))] +#if NET8_0_OR_GREATER [InlineData(nameof(ProductModel.TimeOnly), typeof(TimeOnly?))] +#endif [InlineData(nameof(ProductModel.Guid), typeof(Guid?))] [InlineData(nameof(ProductModel.Decimal), typeof(decimal?))] [InlineData(nameof(ProductModel.Byte), typeof(byte?))] @@ -52,10 +56,14 @@ public void ThrowsCreatingBinaryExpressionCombiningNonNullableParameterWithNulla [InlineData(nameof(Product.DateTime), typeof(DateTime))] [InlineData(nameof(Product.DateTimeOffset), typeof(DateTimeOffset))] [InlineData(nameof(Product.Date), typeof(Date))] +#if NET8_0_OR_GREATER [InlineData(nameof(Product.DateOnly), typeof(DateOnly))] +#endif [InlineData(nameof(Product.TimeSpan), typeof(TimeSpan))] [InlineData(nameof(Product.TimeOfDay), typeof(TimeOfDay))] +#if NET8_0_OR_GREATER [InlineData(nameof(Product.TimeOnly), typeof(TimeOnly))] +#endif [InlineData(nameof(Product.Guid), typeof(Guid))] [InlineData(nameof(Product.Decimal), typeof(decimal))] [InlineData(nameof(Product.Byte), typeof(byte))] @@ -93,10 +101,14 @@ class Product public DateTimeOffset? DateTimeOffset { get; set; } public DateTime? DateTime { get; set; } public Date? Date { get; set; } +#if NET8_0_OR_GREATER public DateOnly? DateOnly { get; set; } +#endif public TimeSpan? TimeSpan { get; set; } public TimeOfDay? TimeOfDay { get; set; } +#if NET8_0_OR_GREATER public TimeOnly? TimeOnly { get; set; } +#endif public Guid? Guid { get; set; } public decimal? Decimal { get; set; } public byte? Byte { get; set; } @@ -118,10 +130,14 @@ class ProductModel public DateTimeOffset DateTimeOffset { get; set; } public DateTime DateTime { get; set; } public Date Date { get; set; } +#if NET8_0_OR_GREATER public DateOnly DateOnly { get; set; } +#endif public TimeSpan TimeSpan { get; set; } public TimeOfDay TimeOfDay { get; set; } +#if NET8_0_OR_GREATER public TimeOnly TimeOnly { get; set; } +#endif public Guid Guid { get; set; } public decimal Decimal { get; set; } public byte Byte { get; set; } diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldUseDeclaringTypeForInstanceMethodCalls.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldUseDeclaringTypeForInstanceMethodCalls.cs index 6db6f2c..2d35e86 100644 --- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldUseDeclaringTypeForInstanceMethodCalls.cs +++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/ShouldUseDeclaringTypeForInstanceMethodCalls.cs @@ -44,8 +44,8 @@ public enum SimpleEnum public record Entity { - public int Id { get; init; } - public SimpleEnum SimpleEnum { get; init; } + public int Id { get; set; } + public SimpleEnum SimpleEnum { get; set; } } public enum SimpleEnumModel @@ -57,8 +57,8 @@ public enum SimpleEnumModel public record EntityModel { - public int Id { get; init; } - public SimpleEnumModel SimpleEnum { get; init; } + public int Id { get; set; } + public SimpleEnumModel SimpleEnum { get; set; } } public class HasFlagVisitor : ExpressionVisitor