From f97ae23a5b9d22b06fbfe88258037e9768dd839f Mon Sep 17 00:00:00 2001 From: Uwe Hey Date: Sat, 27 Aug 2022 17:42:20 +0200 Subject: [PATCH 1/3] - Downshifted to netstandard2.0 to support usage in net48 --- src/Pose/Helpers/StubHelper.cs | 2 +- src/Pose/IL/Stubs.cs | 21 ++++++++++++++------- src/Pose/Pose.csproj | 2 +- test/Pose.Tests/Pose.Tests.csproj | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Pose/Helpers/StubHelper.cs b/src/Pose/Helpers/StubHelper.cs index b6e966d..ea82b76 100644 --- a/src/Pose/Helpers/StubHelper.cs +++ b/src/Pose/Helpers/StubHelper.cs @@ -80,7 +80,7 @@ public static string CreateStubNameFromMethod(string prefix, MethodBase method) if (genericArguments.Length > 0) { name += "["; - name += string.Join(',', genericArguments.Select(g => g.Name)); + name += string.Join(",", genericArguments.Select(g => g.Name)); name += "]"; } } diff --git a/src/Pose/IL/Stubs.cs b/src/Pose/IL/Stubs.cs index 05de1c5..997a3a0 100644 --- a/src/Pose/IL/Stubs.cs +++ b/src/Pose/IL/Stubs.cs @@ -4,6 +4,7 @@ using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; +using System.Runtime.Serialization; using Pose.Helpers; namespace Pose.IL @@ -26,13 +27,19 @@ internal static class Stubs static Stubs() { - s_getMethodFromHandleMethod = typeof(MethodBase).GetMethod("GetMethodFromHandle", new Type[] { typeof(RuntimeMethodHandle), typeof(RuntimeTypeHandle) }); - s_createRewriterMethod = typeof(MethodRewriter).GetMethod("CreateRewriter", new Type[] { typeof(MethodBase), typeof(bool) }); - s_rewriteMethod = typeof(MethodRewriter).GetMethod("Rewrite"); - s_getMethodPointerMethod = typeof(StubHelper).GetMethod("GetMethodPointer"); - s_devirtualizeMethodMethod = typeof(StubHelper).GetMethod("DevirtualizeMethod", new Type[] { typeof(object), typeof(MethodInfo) }); - s_getTypeFromHandleMethod = typeof(Type).GetMethod("GetTypeFromHandle"); - s_getUninitializedObjectMethod = typeof(RuntimeHelpers).GetMethod("GetUninitializedObject"); + s_getMethodFromHandleMethod = typeof(MethodBase).GetMethod(nameof(MethodBase.GetMethodFromHandle), new Type[] { typeof(RuntimeMethodHandle), typeof(RuntimeTypeHandle) }); + s_createRewriterMethod = typeof(MethodRewriter).GetMethod(nameof(MethodRewriter.CreateRewriter), new Type[] { typeof(MethodBase), typeof(bool) }); + s_rewriteMethod = typeof(MethodRewriter).GetMethod(nameof(MethodRewriter.Rewrite)); + s_getMethodPointerMethod = typeof(StubHelper).GetMethod(nameof(StubHelper.GetMethodPointer)); + s_devirtualizeMethodMethod = typeof(StubHelper).GetMethod(nameof(StubHelper.DevirtualizeMethod), new Type[] { typeof(object), typeof(MethodInfo) }); + s_getTypeFromHandleMethod = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle)); + +#if NETSTANDARD2_1 + s_getUninitializedObjectMethod = typeof(RuntimeHelpers).GetMethod(nameof(RuntimeHelpers.GetUninitializedObject)); +#else + // see https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultValueHolder.cs + s_getUninitializedObjectMethod = typeof(FormatterServices).GetMethod(nameof(FormatterServices.GetUninitializedObject)); +#endif } public static DynamicMethod GenerateStubForDirectCall(MethodBase method) diff --git a/src/Pose/Pose.csproj b/src/Pose/Pose.csproj index c664158..261fe13 100644 --- a/src/Pose/Pose.csproj +++ b/src/Pose/Pose.csproj @@ -3,7 +3,7 @@ Pose Replace any .NET method (including static and non-virtual) with a delegate 1.2.1 - netstandard2.1 + netstandard2.0 portable Pose Pose diff --git a/test/Pose.Tests/Pose.Tests.csproj b/test/Pose.Tests/Pose.Tests.csproj index 33d9be3..8bf093e 100644 --- a/test/Pose.Tests/Pose.Tests.csproj +++ b/test/Pose.Tests/Pose.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + netcoreapp3.1;net48 false From e2a50e3c64605c5aaa01803860d7e30fa556fac0 Mon Sep 17 00:00:00 2001 From: Uwe Hey Date: Sat, 27 Aug 2022 19:09:45 +0200 Subject: [PATCH 2/3] - net48 build and tests --- appveyor.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e7ae20d..f2f4932 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,9 @@ -version: '1.2.0.{build}' +version: '1.2.1.{build}' +image: Visual Studio 2022 +environment: + matrix: + - targetframework: net48 + - targetframework: netcoreapp3.1 configuration: - Debug - Release @@ -7,7 +12,7 @@ build_script: - dotnet restore - dotnet build -c %CONFIGURATION% test_script: - - ps: dotnet test .\test\Pose.Tests\Pose.Tests.csproj + - ps: dotnet test -f %TARGETFRAMEWORK% .\test\Pose.Tests\Pose.Tests.csproj - ps: if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } cache: - '%USERPROFILE%\.nuget\packages' From 9c7c46419f554bc9a9e84276404da5cb961f2ea3 Mon Sep 17 00:00:00 2001 From: Uwe Hey Date: Fri, 23 Sep 2022 14:14:36 +0200 Subject: [PATCH 3/3] - remove "old" .net standard 2.1 code --- src/Pose/IL/Stubs.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Pose/IL/Stubs.cs b/src/Pose/IL/Stubs.cs index 997a3a0..a6facc6 100644 --- a/src/Pose/IL/Stubs.cs +++ b/src/Pose/IL/Stubs.cs @@ -34,12 +34,8 @@ static Stubs() s_devirtualizeMethodMethod = typeof(StubHelper).GetMethod(nameof(StubHelper.DevirtualizeMethod), new Type[] { typeof(object), typeof(MethodInfo) }); s_getTypeFromHandleMethod = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle)); -#if NETSTANDARD2_1 - s_getUninitializedObjectMethod = typeof(RuntimeHelpers).GetMethod(nameof(RuntimeHelpers.GetUninitializedObject)); -#else // see https://github.com/dotnet/runtime/blob/main/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/DefaultValueHolder.cs s_getUninitializedObjectMethod = typeof(FormatterServices).GetMethod(nameof(FormatterServices.GetUninitializedObject)); -#endif } public static DynamicMethod GenerateStubForDirectCall(MethodBase method)