diff --git a/src/AutoMapper/AutoMapper.csproj b/src/AutoMapper/AutoMapper.csproj index 78a3402d45..d7512e7297 100644 --- a/src/AutoMapper/AutoMapper.csproj +++ b/src/AutoMapper/AutoMapper.csproj @@ -19,34 +19,20 @@ https://github.com/AutoMapper/AutoMapper/blob/master/LICENSE.txt - - - - - - - - - - - + + + - - - - - - - + diff --git a/src/AutoMapper/Execution/PropertyEmitter.cs b/src/AutoMapper/Execution/PropertyEmitter.cs index b533b86f1d..b66ef74d19 100644 --- a/src/AutoMapper/Execution/PropertyEmitter.cs +++ b/src/AutoMapper/Execution/PropertyEmitter.cs @@ -1,4 +1,3 @@ -#if NET45 || NET40 namespace AutoMapper.Execution { using System; @@ -37,6 +36,9 @@ public PropertyEmitter(TypeBuilder owner, PropertyDescription property, FieldBui _setterBuilder = owner.DefineMethod($"set_{name}", MethodAttributes.Public | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.SpecialName, typeof (void), new[] {propertyType}); + // begin workaround, should be removed when upgrading the .NET Core SDK, https://github.com/dotnet/corefx/issues/7596 + _setterBuilder.DefineParameter(1, ParameterAttributes.In, "_"); + // end workaround ILGenerator setterIl = _setterBuilder.GetILGenerator(); setterIl.Emit(OpCodes.Ldarg_0); setterIl.Emit(OpCodes.Ldarg_1); @@ -65,5 +67,4 @@ public MethodBuilder GetSetter(Type requiredType) ? throw new InvalidOperationException("Types are not compatible") : _setterBuilder; } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/AutoMapper/Execution/ProxyGenerator.cs b/src/AutoMapper/Execution/ProxyGenerator.cs index 10f37591eb..705f7d9cc0 100644 --- a/src/AutoMapper/Execution/ProxyGenerator.cs +++ b/src/AutoMapper/Execution/ProxyGenerator.cs @@ -1,4 +1,3 @@ -#if NET45 || NET40 namespace AutoMapper.Execution { using System; @@ -38,10 +37,10 @@ private static ModuleBuilder CreateProxyModule() name.SetPublicKey(privateKey); name.SetPublicKeyToken(privateKeyToken); -#if NET45 - AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); -#else +#if NET40 AssemblyBuilder builder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); +#else + AssemblyBuilder builder = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run); #endif return builder.DefineDynamicModule("AutoMapper.Proxies.emit"); @@ -59,7 +58,7 @@ private static Type EmitProxy(TypeDescription typeDescription) Debug.WriteLine(name, "Emitting proxy type"); TypeBuilder typeBuilder = proxyModule.DefineType(name, TypeAttributes.Class | TypeAttributes.Sealed | TypeAttributes.Public, typeof(ProxyBase), - interfaceType.IsInterface ? new[] { interfaceType } : Type.EmptyTypes); + interfaceType.IsInterface() ? new[] { interfaceType } : new Type[0]); ConstructorBuilder constructorBuilder = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[0]); ILGenerator ctorIl = constructorBuilder.GetILGenerator(); @@ -242,5 +241,4 @@ public override int GetHashCode() public static bool operator !=(PropertyDescription left, PropertyDescription right) => !left.Equals(right); } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/AutoMapper/Execution/TypeMapPlanBuilder.cs b/src/AutoMapper/Execution/TypeMapPlanBuilder.cs index 12604b3e47..2df33e87f7 100644 --- a/src/AutoMapper/Execution/TypeMapPlanBuilder.cs +++ b/src/AutoMapper/Execution/TypeMapPlanBuilder.cs @@ -280,7 +280,7 @@ private Expression CreateNewDestinationFunc(out bool constructorMapping) constructorMapping = true; return CreateNewDestinationExpression(_typeMap.ConstructorMap); } -#if NET45 || NET40 + if (_typeMap.DestinationTypeToUse.IsInterface()) { var ctor = Call(null, @@ -291,7 +291,7 @@ private Expression CreateNewDestinationFunc(out bool constructorMapping) // We're invoking a delegate here to make it have the right accessibility return Invoke(ctor); } -#endif + return DelegateFactory.GenerateConstructorExpression(_typeMap.DestinationTypeToUse); } diff --git a/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs b/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs index 38ebc89e9e..c8b86b28ff 100644 --- a/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs +++ b/src/AutoMapper/QueryableExtensions/ExpressionBuilder.cs @@ -104,12 +104,10 @@ public LambdaExpression[] CreateMapExpression(ExpressionRequest request, TypePai // this is the input parameter of this expression with name var instanceParameter = Parameter(request.SourceType, "dto"); var expressions = new QueryExpressions(CreateMapExpressionCore(request, instanceParameter, typePairCount, letPropertyMaps, out var typeMap)); -#if NET45 || NET40 if(letPropertyMaps.Count > 0) { expressions = letPropertyMaps.GetSubQueryExpression(this, expressions.First, typeMap, request, instanceParameter, typePairCount); } -#endif if(expressions.First == null) { return null; @@ -436,7 +434,6 @@ bool IsSubQuery() public override LetPropertyMaps New() => new FirstPassLetPropertyMaps(_configurationProvider); -#if NET45 || NET40 public override QueryExpressions GetSubQueryExpression(ExpressionBuilder builder, Expression projection, TypeMap typeMap, ExpressionRequest request, Expression instanceParameter, TypePairCount typePairCount) { var letMapInfos = _savedPaths.Select(path => new @@ -470,7 +467,7 @@ void ReplaceSubQueries() { foreach(var letMapInfo in letMapInfos) { - var letProperty = letType.GetProperty(letMapInfo.Property.Name); + var letProperty = letType.GetDeclaredProperty(letMapInfo.Property.Name); var letPropertyMap = firstTypeMap.FindOrCreatePropertyMapFor(letProperty); letPropertyMap.CustomExpression = Lambda(letMapInfo.MapFrom.ReplaceParameters(letMapInfo.MapFromSource), (ParameterExpression)instanceParameter); @@ -479,7 +476,6 @@ void ReplaceSubQueries() projection = new ReplaceMemberAccessesVisitor(instanceParameter, secondParameter).Visit(projection); } } -#endif class ReplaceMemberAccessesVisitor : ExpressionVisitor { diff --git a/src/AutoMapper/TypeExtensions.cs b/src/AutoMapper/TypeExtensions.cs index c82a146533..2d0460880d 100644 --- a/src/AutoMapper/TypeExtensions.cs +++ b/src/AutoMapper/TypeExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Reflection.Emit; namespace AutoMapper { @@ -21,7 +22,12 @@ internal static class TypeExtensions public static IEnumerable GetDeclaredConstructors(this Type type) => type.GetTypeInfo().DeclaredConstructors; -#if NET45 || NET40 +#if !NET40 && !NET45 + public static MethodInfo GetAddMethod(this EventInfo eventInfo) => eventInfo.AddMethod; + + public static MethodInfo GetRemoveMethod(this EventInfo eventInfo) => eventInfo.RemoveMethod; +#endif + public static Type CreateType(this TypeBuilder type) { #if NET40 @@ -30,7 +36,6 @@ public static Type CreateType(this TypeBuilder type) return type.CreateTypeInfo().AsType(); #endif } -#endif public static IEnumerable GetDeclaredMembers(this Type type) => type.GetTypeInfo().DeclaredMembers; diff --git a/src/UnitTests/DynamicMapping.cs b/src/UnitTests/DynamicMapping.cs index 3962e4cba4..7d37c31c6a 100644 --- a/src/UnitTests/DynamicMapping.cs +++ b/src/UnitTests/DynamicMapping.cs @@ -272,7 +272,6 @@ public void Should_map_new_values() } } -#if NET452 public class When_mapping_from_an_anonymous_type_to_an_interface : NonValidatingSpecBase { private IDestination _result; @@ -295,5 +294,4 @@ public void Should_allow_dynamic_mapping() protected override MapperConfiguration Configuration { get; } = new MapperConfiguration(cfg => cfg.CreateMissingTypeMaps = true); } -#endif } \ No newline at end of file diff --git a/src/UnitTests/InterfaceMapping.cs b/src/UnitTests/InterfaceMapping.cs index eab9c78d80..53e7d21451 100644 --- a/src/UnitTests/InterfaceMapping.cs +++ b/src/UnitTests/InterfaceMapping.cs @@ -1,4 +1,3 @@ -#if NET452 using System; using System.Collections.Generic; using System.ComponentModel; @@ -612,5 +611,4 @@ public void Should_use_the_derived_type_map() } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/UnitTests/Internal/CreateProxyThreading.cs b/src/UnitTests/Internal/CreateProxyThreading.cs index 54458c6e72..ae3dc7853f 100644 --- a/src/UnitTests/Internal/CreateProxyThreading.cs +++ b/src/UnitTests/Internal/CreateProxyThreading.cs @@ -1,5 +1,4 @@ -#if NET452 -using System; +using System; using System.Linq; using System.Threading.Tasks; using AutoMapper.Execution; @@ -35,5 +34,4 @@ public interface ISomeDto } } -} -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/src/UnitTests/Internal/GenerateSimilarType.cs b/src/UnitTests/Internal/GenerateSimilarType.cs index 098a913d0e..2469d18d3d 100644 --- a/src/UnitTests/Internal/GenerateSimilarType.cs +++ b/src/UnitTests/Internal/GenerateSimilarType.cs @@ -1,5 +1,4 @@ -#if NET452 -using System.Linq; +using System.Linq; using System.Collections.Generic; using AutoMapper.Execution; using Xunit; @@ -40,7 +39,7 @@ public void Should_work() var extraProperties = typeof(ExtraProduct).GetProperties().Except(typeof(Product).GetProperties()).Select(p => new PropertyDescription(p)); var similarType = ProxyGenerator.GetSimilarType(typeof(Product), extraProperties); - similarType.Assembly.IsDynamic.ShouldBeTrue(); + similarType.Assembly().IsDynamic.ShouldBeTrue(); var sourceProperties = GetProperties(typeof(ExtraProduct)); var similarTypeProperties = GetProperties(similarType); similarTypeProperties.SequenceEqual(sourceProperties).ShouldBeTrue(); @@ -69,5 +68,4 @@ public IEnumerable GetProperties(Type type) return type.GetProperties().OrderBy(p => p.Name).Select(p => new { p.Name, p.PropertyType }); } } -} -#endif \ No newline at end of file +} \ No newline at end of file