From 79779d76175c18a8d8fbfda068505515a88a485d Mon Sep 17 00:00:00 2001 From: aetos Date: Mon, 19 Oct 2026 10:46:23 +0900 Subject: [PATCH 1/7] test: run tests against the netstandard2.1 build Add MemoryPack.Tests.NetStandard, which links the sources of MemoryPack.Tests and references MemoryPack.Core and MemoryPack.Streaming with SetTargetFramework=netstandard2.1. NET*_OR_GREATER symbols are disabled so that test code and generated code take the same path as netstandard2.1 consumers (e.g. Unity). - Exclude source generator tests and MemoryLayoutTest, which do not depend on the target framework of the libraries. - Skip SerializerStructBufferWriterTest when NET7_0_OR_GREATER is not defined, because the netstandard2.1 build requires TBufferWriter to be a reference type. - Register external union formatters manually in UnionTest when NET5_0_OR_GREATER is not defined, because generated initializers have [ModuleInitializer] only in that case. Co-Authored-By: Claude Opus 5.5 --- MemoryPack.sln | 9 ++++ .../MemoryPack.Tests.NetStandard.csproj | 52 +++++++++++++++++++ .../SerializerStructBufferWriterTest.cs | 7 ++- tests/MemoryPack.Tests/UnionTest.cs | 12 +++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj diff --git a/MemoryPack.sln b/MemoryPack.sln index 57481e1c..08550d3f 100644 --- a/MemoryPack.sln +++ b/MemoryPack.sln @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Net6VsNet7", "sandbox\Net6V EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.UnityShims", "src\MemoryPack.UnityShims\MemoryPack.UnityShims.csproj", "{9339C66C-25E5-4130-A213-9BA1804AD562}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Tests.NetStandard", "tests\MemoryPack.Tests.NetStandard\MemoryPack.Tests.NetStandard.csproj", "{B498EF75-D4BB-4B60-B15D-A9DD4059275A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -128,6 +130,12 @@ Global {9339C66C-25E5-4130-A213-9BA1804AD562}.Release|Any CPU.Build.0 = Release|Any CPU {9339C66C-25E5-4130-A213-9BA1804AD562}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU {9339C66C-25E5-4130-A213-9BA1804AD562}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU + {B498EF75-D4BB-4B60-B15D-A9DD4059275A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B498EF75-D4BB-4B60-B15D-A9DD4059275A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B498EF75-D4BB-4B60-B15D-A9DD4059275A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B498EF75-D4BB-4B60-B15D-A9DD4059275A}.Release|Any CPU.Build.0 = Release|Any CPU + {B498EF75-D4BB-4B60-B15D-A9DD4059275A}.WinBenchmark|Any CPU.ActiveCfg = Release|Any CPU + {B498EF75-D4BB-4B60-B15D-A9DD4059275A}.WinBenchmark|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -147,6 +155,7 @@ Global {6E18AECF-34B2-48F9-9694-54150FB156EB} = {796FB992-A35C-405B-82A7-4C90C5673174} {5612B811-586A-4EB3-9AE7-60CAD4969A1B} = {796FB992-A35C-405B-82A7-4C90C5673174} {9339C66C-25E5-4130-A213-9BA1804AD562} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF} + {B498EF75-D4BB-4B60-B15D-A9DD4059275A} ={204004F9-9B91-4DD1-812C-80D629169ED5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {01ADF7A3-0758-4A3C-9A18-AEF0F30B6E1B} diff --git a/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj b/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj new file mode 100644 index 00000000..1a5b4717 --- /dev/null +++ b/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj @@ -0,0 +1,52 @@ + + + + + + net8.0 + enable + true + MemoryPack.Tests + + true + + + + + + + + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + Analyzer + false + + + + + + + + + + + + diff --git a/tests/MemoryPack.Tests/SerializerStructBufferWriterTest.cs b/tests/MemoryPack.Tests/SerializerStructBufferWriterTest.cs index 191da0ad..aed8b59d 100644 --- a/tests/MemoryPack.Tests/SerializerStructBufferWriterTest.cs +++ b/tests/MemoryPack.Tests/SerializerStructBufferWriterTest.cs @@ -1,4 +1,7 @@ -using System; +#if NET7_0_OR_GREATER +// netstandard2.1 build of MemoryPack requires TBufferWriter to be a reference type. + +using System; using System.Buffers; using MemoryPack.Tests.Models; @@ -57,3 +60,5 @@ public Span GetSpan(int sizeHint = 0) return new byte[sizeHint]; } } + +#endif diff --git a/tests/MemoryPack.Tests/UnionTest.cs b/tests/MemoryPack.Tests/UnionTest.cs index 9a614a39..34509b8d 100644 --- a/tests/MemoryPack.Tests/UnionTest.cs +++ b/tests/MemoryPack.Tests/UnionTest.cs @@ -10,6 +10,18 @@ namespace MemoryPack.Tests; public class UnionTest { +#if !NET5_0_OR_GREATER + public UnionTest() + { + // Required for MemoryPack.Tests.NetStandard, which disables NET*_OR_GREATER symbols. + // Generated initializers have [ModuleInitializer] only when NET5_0_OR_GREATER is defined, + // so the union formatters must be registered manually otherwise (same as Unity). + ForExternalUnionFormatterInitializer.RegisterFormatter(); + ForExternalUnionFormatter2_T_Initializer.RegisterFormatter(); + ForExternalUnionFormatter3Initializer.RegisterFormatter(); + } +#endif + [Fact] public void Foo() { From 2b5865eb1f6f07f9d184c6c650e9c86c08049d84 Mon Sep 17 00:00:00 2001 From: aetos Date: Mon, 19 Oct 2026 14:27:03 +0900 Subject: [PATCH 2/7] test: update Microsoft.NET.Test.Sdk to 17.14.1 Microsoft.NET.Test.Sdk 17.3.1 is distributed under the Microsoft .NET Library license (LICENSE_NET.txt), which is not in the allow list of dependency-review. 17.10.0 and later use the MIT license expression. Update both test projects to the same version, because they share the same test sources. Co-Authored-By: Claude Opus 5.5 --- .../MemoryPack.Tests.NetStandard.csproj | 2 +- tests/MemoryPack.Tests/MemoryPack.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj b/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj index 1a5b4717..384f5c55 100644 --- a/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj +++ b/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj @@ -24,7 +24,7 @@ - + diff --git a/tests/MemoryPack.Tests/MemoryPack.Tests.csproj b/tests/MemoryPack.Tests/MemoryPack.Tests.csproj index 313cbe3e..7c176fa7 100644 --- a/tests/MemoryPack.Tests/MemoryPack.Tests.csproj +++ b/tests/MemoryPack.Tests/MemoryPack.Tests.csproj @@ -9,7 +9,7 @@ - + From 7ad99d568e38cdf8b016acbdde871040606d4114 Mon Sep 17 00:00:00 2001 From: aetos Date: Thu, 12 Nov 2026 17:19:21 +0900 Subject: [PATCH 3/7] build: target netstandard2.1, net8.0 and net10.0 - Drop net7.0 from the libraries and add net10.0. MemoryPack.Streaming also gets net8.0, so that .NET 8 apps keep using the net* builds of both MemoryPack.Core and MemoryPack.Streaming. - MemoryPack.AspNetCoreMvcFormatter: net6.0;net7.0 -> net8.0;net10.0. - The source generator switches the generated code by NET8_0_OR_GREATER instead of NET7_0_OR_GREATER, because apps on .NET 7 or lower now resolve to the netstandard2.1 build. MEMPACK034 keeps NET7_0_OR_GREATER, as it is about the struct layout of the runtime. - Reference System.IO.Pipelines only below net9.0. It is part of the shared framework in .NET 9 or later. - Run the tests on net8.0 and net10.0, and the netstandard2.1 tests on net10.0. - SandboxWebApp: net7.0 -> net10.0. Co-Authored-By: Claude Opus 5.5 --- sandbox/SandboxWebApp/SandboxWebApp.csproj | 2 +- .../MemoryPack.AspNetCoreMvcFormatter.csproj | 2 +- src/MemoryPack.Core/MemoryPack.Core.csproj | 2 +- src/MemoryPack.Generator/IGeneratorContext.cs | 5 +++-- .../MemoryPackGenerator.Emitter.cs | 14 +++++++------- src/MemoryPack.Generator/MemoryPackGenerator.cs | 17 +++++++++++------ .../MemoryPack.Streaming.csproj | 5 +++-- .../MemoryPack.UnityShims.csproj | 2 +- src/MemoryPack/MemoryPack.csproj | 2 +- .../MemoryPack.Tests.NetStandard.csproj | 2 +- tests/MemoryPack.Tests/MemoryPack.Tests.csproj | 2 +- .../Utils/CSharpGeneratorRunner.cs | 2 +- 12 files changed, 32 insertions(+), 25 deletions(-) diff --git a/sandbox/SandboxWebApp/SandboxWebApp.csproj b/sandbox/SandboxWebApp/SandboxWebApp.csproj index b9a4d215..5b3d0d6f 100644 --- a/sandbox/SandboxWebApp/SandboxWebApp.csproj +++ b/sandbox/SandboxWebApp/SandboxWebApp.csproj @@ -1,7 +1,7 @@  - net7.0 + net10.0 enable enable diff --git a/src/MemoryPack.AspNetCoreMvcFormatter/MemoryPack.AspNetCoreMvcFormatter.csproj b/src/MemoryPack.AspNetCoreMvcFormatter/MemoryPack.AspNetCoreMvcFormatter.csproj index 08862cea..b9b72234 100644 --- a/src/MemoryPack.AspNetCoreMvcFormatter/MemoryPack.AspNetCoreMvcFormatter.csproj +++ b/src/MemoryPack.AspNetCoreMvcFormatter/MemoryPack.AspNetCoreMvcFormatter.csproj @@ -1,7 +1,7 @@ - net7.0;net6.0 + net8.0;net10.0 Library enable enable diff --git a/src/MemoryPack.Core/MemoryPack.Core.csproj b/src/MemoryPack.Core/MemoryPack.Core.csproj index c3d8e842..237dc21c 100644 --- a/src/MemoryPack.Core/MemoryPack.Core.csproj +++ b/src/MemoryPack.Core/MemoryPack.Core.csproj @@ -1,7 +1,7 @@  - net7.0;net8.0;netstandard2.1 + netstandard2.1;net8.0;net10.0 enable enable True diff --git a/src/MemoryPack.Generator/IGeneratorContext.cs b/src/MemoryPack.Generator/IGeneratorContext.cs index d155ef8b..e395addd 100644 --- a/src/MemoryPack.Generator/IGeneratorContext.cs +++ b/src/MemoryPack.Generator/IGeneratorContext.cs @@ -10,8 +10,9 @@ public interface IGeneratorContext void ReportDiagnostic(Diagnostic diagnostic); void AddSource(string hintName, string source); LanguageVersion LanguageVersion { get; } - bool IsNet7OrGreater { get; } - bool IsNet10OrGreater { get; } + bool IsNet7OrGreater { get; } // for the struct layout of the runtime(MEMPACK034), not for the build of MemoryPack + bool IsNet8OrGreater { get; } // uses the net* build of MemoryPack(net8.0 is the lowest net* target), otherwise the netstandard2.1 build + bool IsNet10OrGreater { get; } // for the DateTimeOffset layout of the runtime(MEMPACK043) bool IsUnityCompilation { get; } // has UNITY_*** symbol bool IsForUnity { get; } } diff --git a/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs b/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs index d17735fa..32074467 100644 --- a/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs +++ b/src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs @@ -333,7 +333,7 @@ public void Emit(StringBuilder writer, IGeneratorContext context) scopedRef = (context.IsCSharp11OrGreater()) ? "scoped ref" : "ref"; - if (!context.IsNet7OrGreater) + if (!context.IsNet8OrGreater) { staticRegisterFormatterMethod = "public static void "; staticMemoryPackableMethod = "public static void "; @@ -428,7 +428,7 @@ public void Emit(StringBuilder writer, IGeneratorContext context) } """); - if (!context.IsNet7OrGreater) + if (!context.IsNet8OrGreater) { // add formatter(can not use MemoryPackableFormatter) @@ -603,7 +603,7 @@ string EmitAdditionalRegisterFormatter(string indent, IGeneratorContext context) .Where(x => x.Item2 != null) .Where(x => { - if (!context.IsNet7OrGreater) + if (!context.IsNet8OrGreater) { if (x.Item2!.StartsWith("global::MemoryPack.Formatters.InterfaceReadOnlySetFormatter")) { @@ -978,10 +978,10 @@ string EmitUnionTemplate(IGeneratorContext context) { var classOrInterfaceOrRecord = IsRecord ? "record" : (Symbol.TypeKind == TypeKind.Interface) ? "interface" : "class"; - var staticRegisterFormatterMethod = (context.IsNet7OrGreater) + var staticRegisterFormatterMethod = (context.IsNet8OrGreater) ? $"static void IMemoryPackFormatterRegister." : "public static void "; - var register = (context.IsNet7OrGreater) + var register = (context.IsNet8OrGreater) ? $"global::MemoryPack.MemoryPackFormatterProvider.Register<{TypeName}>();" : "RegisterFormatter();"; var scopedRef = context.IsCSharp11OrGreater() @@ -1238,10 +1238,10 @@ string EmitGenericCollectionTemplate(IGeneratorContext context) var typeArgs = string.Join(", ", collectionSymbol!.TypeArguments.Select(x => x.FullyQualifiedToString())); - var staticRegisterFormatterMethod = (context.IsNet7OrGreater) + var staticRegisterFormatterMethod = (context.IsNet8OrGreater) ? $"static void IMemoryPackFormatterRegister." : "public static void "; - var register = (context.IsNet7OrGreater) + var register = (context.IsNet8OrGreater) ? $"global::MemoryPack.MemoryPackFormatterProvider.Register<{TypeName}>();" : "RegisterFormatter();"; diff --git a/src/MemoryPack.Generator/MemoryPackGenerator.cs b/src/MemoryPack.Generator/MemoryPackGenerator.cs index 57300f62..bfdfb06e 100644 --- a/src/MemoryPack.Generator/MemoryPackGenerator.cs +++ b/src/MemoryPack.Generator/MemoryPackGenerator.cs @@ -64,9 +64,11 @@ void RegisterMemoryPackable(IncrementalGeneratorInitializationContext context) var csOptions = (CSharpParseOptions)parseOptions; var langVersion = csOptions.LanguageVersion; var net7 = csOptions.PreprocessorSymbolNames.Contains("NET7_0_OR_GREATER"); + // net8.0 is the lowest net* target of MemoryPack, lower targets resolve to the netstandard2.1 build. + var net8 = csOptions.PreprocessorSymbolNames.Contains("NET8_0_OR_GREATER"); var net10 = csOptions.PreprocessorSymbolNames.Contains("NET10_0_OR_GREATER"); var unity = csOptions.PreprocessorSymbolNames.Any(x => x.StartsWith("UNITY_", StringComparison.Ordinal)); - return (langVersion, net7, net10, unity); + return (langVersion, net7, net8, net10, unity); }) .WithTrackingName("MemoryPack.MemoryPackable.0_ParseOptionsProvider"); @@ -110,9 +112,9 @@ or RecordDeclarationSyntax { var (typeDeclaration, compilation) = source.Left.Item1; var logPath = source.Left.Item2; - var (langVersion, net7, net10, unity) = source.Right; + var (langVersion, net7, net8, net10, unity) = source.Right; - Generate(typeDeclaration, compilation, logPath, new GeneratorContext(context, langVersion, net7, net10, unity)); + Generate(typeDeclaration, compilation, logPath, new GeneratorContext(context, langVersion, net7, net8, net10, unity)); }); } { @@ -127,9 +129,9 @@ or RecordDeclarationSyntax { var (typeDeclaration, compilation) = source.Left.Item1; var logPath = source.Left.Item2; - var (langVersion, net7, net10, unity) = source.Right; + var (langVersion, net7, net8, net10, unity) = source.Right; - Generate(typeDeclaration, compilation, logPath, new GeneratorContext(context, langVersion, net7, net10, unity)); + Generate(typeDeclaration, compilation, logPath, new GeneratorContext(context, langVersion, net7, net8, net10, unity)); }); } } @@ -299,11 +301,12 @@ class GeneratorContext : IGeneratorContext { SourceProductionContext context; - public GeneratorContext(SourceProductionContext context, LanguageVersion languageVersion, bool isNet70OrGreater, bool isNet100OrGreater, bool isUnityCompilation) + public GeneratorContext(SourceProductionContext context, LanguageVersion languageVersion, bool isNet70OrGreater, bool isNet80OrGreater, bool isNet100OrGreater, bool isUnityCompilation) { this.context = context; this.LanguageVersion = languageVersion; this.IsNet7OrGreater = isNet70OrGreater; + this.IsNet8OrGreater = isNet80OrGreater; this.IsNet10OrGreater = isNet100OrGreater; this.IsUnityCompilation = isUnityCompilation; } @@ -314,6 +317,8 @@ public GeneratorContext(SourceProductionContext context, LanguageVersion languag public bool IsNet7OrGreater { get; } + public bool IsNet8OrGreater { get; } + public bool IsNet10OrGreater { get; } public bool IsUnityCompilation { get; } diff --git a/src/MemoryPack.Streaming/MemoryPack.Streaming.csproj b/src/MemoryPack.Streaming/MemoryPack.Streaming.csproj index a7d0c209..07b7e544 100644 --- a/src/MemoryPack.Streaming/MemoryPack.Streaming.csproj +++ b/src/MemoryPack.Streaming/MemoryPack.Streaming.csproj @@ -1,7 +1,7 @@  - net7.0;netstandard2.1 + netstandard2.1;net8.0;net10.0 enable enable $(NoWarn);CS1591;CA2255 @@ -13,7 +13,8 @@ Additional streaming support for MemoryPack. - + + diff --git a/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj b/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj index 7ac25d91..5e5a78eb 100644 --- a/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj +++ b/src/MemoryPack.UnityShims/MemoryPack.UnityShims.csproj @@ -1,7 +1,7 @@  - net7.0;net8.0;netstandard2.1 + netstandard2.1;net8.0;net10.0 enable enable True diff --git a/src/MemoryPack/MemoryPack.csproj b/src/MemoryPack/MemoryPack.csproj index 76774794..667e71a8 100644 --- a/src/MemoryPack/MemoryPack.csproj +++ b/src/MemoryPack/MemoryPack.csproj @@ -1,7 +1,7 @@ - net7.0;net8.0;netstandard2.1 + netstandard2.1;net8.0;net10.0 false true diff --git a/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj b/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj index 384f5c55..b1a3822a 100644 --- a/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj +++ b/tests/MemoryPack.Tests.NetStandard/MemoryPack.Tests.NetStandard.csproj @@ -3,7 +3,7 @@ - net8.0 + net10.0 enable true MemoryPack.Tests diff --git a/tests/MemoryPack.Tests/MemoryPack.Tests.csproj b/tests/MemoryPack.Tests/MemoryPack.Tests.csproj index 7c176fa7..0101f99c 100644 --- a/tests/MemoryPack.Tests/MemoryPack.Tests.csproj +++ b/tests/MemoryPack.Tests/MemoryPack.Tests.csproj @@ -1,7 +1,7 @@  - net8.0 + net8.0;net10.0 enable true diff --git a/tests/MemoryPack.Tests/Utils/CSharpGeneratorRunner.cs b/tests/MemoryPack.Tests/Utils/CSharpGeneratorRunner.cs index 914069f4..2ececa35 100644 --- a/tests/MemoryPack.Tests/Utils/CSharpGeneratorRunner.cs +++ b/tests/MemoryPack.Tests/Utils/CSharpGeneratorRunner.cs @@ -49,7 +49,7 @@ public static (Compilation, ImmutableArray) RunGenerator(string sour { if (preprocessorSymbols == null) { - preprocessorSymbols = new[] { "NET7_0_OR_GREATER" }; + preprocessorSymbols = new[] { "NET7_0_OR_GREATER", "NET8_0_OR_GREATER" }; } var parseOptions = new CSharpParseOptions(LanguageVersion.CSharp11, preprocessorSymbols: preprocessorSymbols); From 66df7f5d0896ab11c2061c2e03106b23fdb4d4c4 Mon Sep 17 00:00:00 2001 From: aetos Date: Thu, 12 Nov 2026 17:19:30 +0900 Subject: [PATCH 4/7] refactor: use NETSTANDARD instead of NET5/7/8_0_OR_GREATER Now that net7.0 is dropped, NET5_0_OR_GREATER, NET7_0_OR_GREATER and NET8_0_OR_GREATER all mean "not the netstandard2.1 build" in MemoryPack.Core. The behavior of each build is not changed. The code generated by the source generator and the test code keep the original symbols, because they are compiled with the symbols of the consuming project. Co-Authored-By: Claude Opus 5.5 --- .../Compression/BitPackFormatter.cs | 6 ++-- .../Compression/BrotliCompressor.cs | 14 ++++---- .../Formatters/CollectionFormatters.cs | 20 +++++------ .../Formatters/FrozenCollectionFormatter.cs | 2 +- .../ImmutableCollectionFormatters.cs | 2 +- .../InterfaceCollectionFormatters.cs | 12 +++---- .../Formatters/KeyValuePairFormatter.cs | 2 +- .../Formatters/MemoryPackableFormatter.cs | 2 +- .../MultiDimensionalArrayFormatters.cs | 12 +++---- .../Formatters/StringBuilderFormatter.cs | 2 +- .../Formatters/TypeFormatter.cs | 2 +- src/MemoryPack.Core/IMemoryPackFormatter.cs | 6 ++-- src/MemoryPack.Core/IMemoryPackable.cs | 6 ++-- .../Internal/EnumerableExtensions.cs | 2 +- .../Internal/MemoryMarshalEx.cs | 2 +- .../ReusableLinkedArrayBufferWriter.cs | 10 +++--- .../ReusableReadOnlySequenceBuilder.cs | 4 +-- src/MemoryPack.Core/Internal/TypeHelpers.cs | 2 +- ...oryPackFormatterProvider.WellknownTypes.cs | 2 +- ...oryPackFormatterProvider.WellknownTypes.tt | 2 +- .../MemoryPackFormatterProvider.cs | 6 ++-- src/MemoryPack.Core/MemoryPackReader.cs | 34 +++++++++---------- .../MemoryPackSerializer.Deserialize.cs | 10 +++--- .../MemoryPackSerializer.NonGenerics.cs | 4 +-- .../MemoryPackSerializer.Serialize.cs | 10 +++--- .../MemoryPackSerializerOptions.cs | 2 +- src/MemoryPack.Core/MemoryPackWriter.cs | 34 +++++++++---------- .../MemoryPackWriterOptionalState.cs | 2 +- 28 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/MemoryPack.Core/Compression/BitPackFormatter.cs b/src/MemoryPack.Core/Compression/BitPackFormatter.cs index 55dae4dd..94d58348 100644 --- a/src/MemoryPack.Core/Compression/BitPackFormatter.cs +++ b/src/MemoryPack.Core/Compression/BitPackFormatter.cs @@ -1,7 +1,7 @@ using MemoryPack.Internal; using System.Runtime.CompilerServices; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using System.Runtime.InteropServices; using System.Runtime.Intrinsics; #endif @@ -28,14 +28,14 @@ public override void Serialize(ref MemoryPackWriter= 32) { ref var loopEnd = ref Unsafe.Subtract(ref end, 32); diff --git a/src/MemoryPack.Core/Compression/BrotliCompressor.cs b/src/MemoryPack.Core/Compression/BrotliCompressor.cs index 9279addb..d6548550 100644 --- a/src/MemoryPack.Core/Compression/BrotliCompressor.cs +++ b/src/MemoryPack.Core/Compression/BrotliCompressor.cs @@ -7,12 +7,12 @@ namespace MemoryPack.Compression; -#if !NET7_0_OR_GREATER +#if NETSTANDARD #pragma warning disable CS8602 #endif public -#if NET7_0_OR_GREATER +#if !NETSTANDARD struct #else class @@ -23,7 +23,7 @@ namespace MemoryPack.Compression; readonly int quality; readonly int window; -#if NET7_0_OR_GREATER +#if !NETSTANDARD public BrotliCompressor() : this(CompressionLevel.Fastest) @@ -195,7 +195,7 @@ public async ValueTask CopyToAsync(Stream stream, int bufferSize = 65535, Cancel } public void CopyTo(ref MemoryPackWriter memoryPackWriter) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -253,7 +253,7 @@ static int CompressCore(ref BrotliEncoder encoder, ReadOnlySpan(ref BrotliEncoder encoder, ReadOnlySpan source, ref MemoryPackWriter destBufferWriter, int? initialLength, bool isFinalBlock) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -295,7 +295,7 @@ public void Dispose() bufferWriter = null!; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD [MemberNotNull(nameof(bufferWriter))] #endif void ThrowIfDisposed() @@ -323,7 +323,7 @@ internal static int GetQualityFromCompressionLevel(CompressionLevel compressionL CompressionLevel.NoCompression => Quality_Min, CompressionLevel.Fastest => 1, CompressionLevel.Optimal => Quality_Default, -#if NET7_0_OR_GREATER +#if !NETSTANDARD CompressionLevel.SmallestSize => Quality_Max, #endif _ => throw new ArgumentException() diff --git a/src/MemoryPack.Core/Formatters/CollectionFormatters.cs b/src/MemoryPack.Core/Formatters/CollectionFormatters.cs index 28e7c68e..c4b7f298 100644 --- a/src/MemoryPack.Core/Formatters/CollectionFormatters.cs +++ b/src/MemoryPack.Core/Formatters/CollectionFormatters.cs @@ -27,7 +27,7 @@ public static partial class MemoryPackFormatterProvider { typeof(LinkedList<>), typeof(LinkedListFormatter<>) }, { typeof(HashSet<>), typeof(HashSetFormatter<>) }, { typeof(SortedSet<>), typeof(SortedSetFormatter<>) }, -#if NET7_0_OR_GREATER +#if !NETSTANDARD { typeof(PriorityQueue<,>), typeof(PriorityQueueFormatter<,>) }, #endif { typeof(ObservableCollection<>), typeof(ObservableCollectionFormatter<>) }, @@ -55,7 +55,7 @@ public static class ListFormatter [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SerializePackable(ref MemoryPackWriter writer, List? value) where T : IMemoryPackable -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -67,7 +67,7 @@ public static void SerializePackable(ref MemoryPackWriter(); @@ -105,7 +105,7 @@ public static void DeserializePackable(ref MemoryPackReader reader, scoped re { value = new List(length); } -#if NET8_0_OR_GREATER +#if !NETSTANDARD else if (value.Count == length) { value.Clear(); @@ -142,7 +142,7 @@ public override void Serialize(ref MemoryPackWriter(); @@ -168,7 +168,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref List(length); } -#if NET8_0_OR_GREATER +#if !NETSTANDARD else if (value.Count == length) { value.Clear(); @@ -259,7 +259,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref Stack : MemoryPackFormatter> diff --git a/src/MemoryPack.Core/Formatters/FrozenCollectionFormatter.cs b/src/MemoryPack.Core/Formatters/FrozenCollectionFormatter.cs index 9214b7e8..f58660f9 100644 --- a/src/MemoryPack.Core/Formatters/FrozenCollectionFormatter.cs +++ b/src/MemoryPack.Core/Formatters/FrozenCollectionFormatter.cs @@ -1,4 +1,4 @@ -#if NET8_0_OR_GREATER +#if !NETSTANDARD using MemoryPack.Formatters; using MemoryPack.Internal; using System.Collections.Frozen; diff --git a/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs b/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs index 3e398176..79a52275 100644 --- a/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs +++ b/src/MemoryPack.Core/Formatters/ImmutableCollectionFormatters.cs @@ -51,7 +51,7 @@ public override void Serialize(ref MemoryPackWriter value) { -#if NET8_0_OR_GREATER +#if !NETSTANDARD var array = reader.ReadArray(); if (array == null) { diff --git a/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs b/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs index 6a5d819d..69147ef4 100644 --- a/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs +++ b/src/MemoryPack.Core/Formatters/InterfaceCollectionFormatters.cs @@ -26,7 +26,7 @@ public static partial class MemoryPackFormatterProvider { typeof(ILookup<,>), typeof(InterfaceLookupFormatter<,>) }, { typeof(IGrouping<,>), typeof(InterfaceGroupingFormatter<,>) }, { typeof(ISet<>), typeof(InterfaceSetFormatter<>) }, -#if NET7_0_OR_GREATER +#if !NETSTANDARD { typeof(IReadOnlySet<>), typeof(InterfaceReadOnlySetFormatter<>) }, #endif }; @@ -42,7 +42,7 @@ file static class InterfaceCollectionFormatterUtils [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool TrySerializeOptimized(ref MemoryPackWriter writer, [NotNullWhen(false)] scoped ref TCollection? value) where TCollection : IEnumerable -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -62,7 +62,7 @@ public static bool TrySerializeOptimized(r return true; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD if (value is List list) { writer.WriteSpan(CollectionsMarshal.AsSpan(list)); @@ -75,7 +75,7 @@ public static bool TrySerializeOptimized(r public static void SerializeCollection(ref MemoryPackWriter writer, scoped ref TCollection? value) where TCollection : ICollection -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -94,7 +94,7 @@ public static void SerializeCollection(ref public static void SerializeReadOnlyCollection(ref MemoryPackWriter writer, scoped ref TCollection? value) where TCollection : IReadOnlyCollection -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -572,7 +572,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref ISet : MemoryPackFormatter> diff --git a/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs b/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs index 936452cb..0975f80d 100644 --- a/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs +++ b/src/MemoryPack.Core/Formatters/KeyValuePairFormatter.cs @@ -12,7 +12,7 @@ public static class KeyValuePairFormatter [Preserve] [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Serialize(IMemoryPackFormatter keyFormatter, IMemoryPackFormatter valueFormatter, ref MemoryPackWriter writer, KeyValuePair value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter diff --git a/src/MemoryPack.Core/Formatters/MemoryPackableFormatter.cs b/src/MemoryPack.Core/Formatters/MemoryPackableFormatter.cs index 752dac6b..1c4f381e 100644 --- a/src/MemoryPack.Core/Formatters/MemoryPackableFormatter.cs +++ b/src/MemoryPack.Core/Formatters/MemoryPackableFormatter.cs @@ -3,7 +3,7 @@ namespace MemoryPack.Formatters; -#if NET7_0_OR_GREATER +#if !NETSTANDARD [Preserve] public sealed class MemoryPackableFormatter : MemoryPackFormatter diff --git a/src/MemoryPack.Core/Formatters/MultiDimensionalArrayFormatters.cs b/src/MemoryPack.Core/Formatters/MultiDimensionalArrayFormatters.cs index 96d0c253..094085ab 100644 --- a/src/MemoryPack.Core/Formatters/MultiDimensionalArrayFormatters.cs +++ b/src/MemoryPack.Core/Formatters/MultiDimensionalArrayFormatters.cs @@ -25,7 +25,7 @@ public override void Serialize(ref MemoryPackWriter()) { var byteCount = Unsafe.SizeOf() * i * j; @@ -86,7 +86,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref T?[,]? value = new T[iLength, jLength]; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD if (!RuntimeHelpers.IsReferenceOrContainsReferences()) { var byteCount = checked(Unsafe.SizeOf() * iLength * jLength); @@ -143,7 +143,7 @@ public override void Serialize(ref MemoryPackWriter()) { var byteCount = Unsafe.SizeOf() * i * j * k; @@ -203,7 +203,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref T?[,,]? value = new T[iLength, jLength, kLength]; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD if (!RuntimeHelpers.IsReferenceOrContainsReferences()) { var byteCount = checked(Unsafe.SizeOf() * iLength * jLength * kLength); @@ -268,7 +268,7 @@ public override void Serialize(ref MemoryPackWriter()) { var byteCount = Unsafe.SizeOf() * i * j * k * l; @@ -328,7 +328,7 @@ public override void Deserialize(ref MemoryPackReader reader, scoped ref T?[,,,] value = new T[iLength, jLength, kLength, lLength]; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD if (!RuntimeHelpers.IsReferenceOrContainsReferences()) { var byteCount = checked(Unsafe.SizeOf() * iLength * jLength * kLength * lLength); diff --git a/src/MemoryPack.Core/Formatters/StringBuilderFormatter.cs b/src/MemoryPack.Core/Formatters/StringBuilderFormatter.cs index 65e23c06..06f4bde2 100644 --- a/src/MemoryPack.Core/Formatters/StringBuilderFormatter.cs +++ b/src/MemoryPack.Core/Formatters/StringBuilderFormatter.cs @@ -17,7 +17,7 @@ public override void Serialize(ref MemoryPackWriter // Result will be "TypeName, Assembly" // see:http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx -#if NET7_0_OR_GREATER +#if !NETSTANDARD [GeneratedRegex(@", Version=\d+.\d+.\d+.\d+, Culture=[\w-]+, PublicKeyToken=(?:null|[a-f0-9]{16})")] private static partial Regex ShortTypeNameRegex(); diff --git a/src/MemoryPack.Core/IMemoryPackFormatter.cs b/src/MemoryPack.Core/IMemoryPackFormatter.cs index 0ce82e91..a89ab3bc 100644 --- a/src/MemoryPack.Core/IMemoryPackFormatter.cs +++ b/src/MemoryPack.Core/IMemoryPackFormatter.cs @@ -8,7 +8,7 @@ public interface IMemoryPackFormatter { [Preserve] void Serialize(ref MemoryPackWriter writer, scoped ref object? value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter; #else where TBufferWriter : class, IBufferWriter; @@ -22,7 +22,7 @@ public interface IMemoryPackFormatter { [Preserve] void Serialize(ref MemoryPackWriter writer, scoped ref T? value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter; #else where TBufferWriter : class, IBufferWriter; @@ -36,7 +36,7 @@ public abstract class MemoryPackFormatter : IMemoryPackFormatter, IMemoryP { [Preserve] public abstract void Serialize(ref MemoryPackWriter writer, scoped ref T? value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter; #else where TBufferWriter : class, IBufferWriter; diff --git a/src/MemoryPack.Core/IMemoryPackable.cs b/src/MemoryPack.Core/IMemoryPackable.cs index ed228006..89b7071b 100644 --- a/src/MemoryPack.Core/IMemoryPackable.cs +++ b/src/MemoryPack.Core/IMemoryPackable.cs @@ -2,7 +2,7 @@ namespace MemoryPack; -#if NET7_0_OR_GREATER +#if !NETSTANDARD public interface IFixedSizeMemoryPackable { @@ -13,7 +13,7 @@ public interface IFixedSizeMemoryPackable public interface IMemoryPackFormatterRegister { -#if NET7_0_OR_GREATER +#if !NETSTANDARD static abstract void RegisterFormatter(); #endif } @@ -23,7 +23,7 @@ public interface IMemoryPackable : IMemoryPackFormatterRegister // note: serialize parameter should be `ref readonly` but current lang spec can not. // see proposal https://github.com/dotnet/csharplang/issues/6010 -#if NET7_0_OR_GREATER +#if !NETSTANDARD static abstract void Serialize(ref MemoryPackWriter writer, scoped ref T? value) where TBufferWriter : IBufferWriter; static abstract void Deserialize(ref MemoryPackReader reader, scoped ref T? value); diff --git a/src/MemoryPack.Core/Internal/EnumerableExtensions.cs b/src/MemoryPack.Core/Internal/EnumerableExtensions.cs index a6f18369..b7601928 100644 --- a/src/MemoryPack.Core/Internal/EnumerableExtensions.cs +++ b/src/MemoryPack.Core/Internal/EnumerableExtensions.cs @@ -7,7 +7,7 @@ public static bool TryGetNonEnumeratedCountEx(this IEnumerable value, out // TryGetNonEnumeratedCount is not check IReadOnlyCollection so add check manually. // https://github.com/dotnet/runtime/issues/54764 -#if NET7_0_OR_GREATER +#if !NETSTANDARD if (value.TryGetNonEnumeratedCount(out count)) { return true; diff --git a/src/MemoryPack.Core/Internal/MemoryMarshalEx.cs b/src/MemoryPack.Core/Internal/MemoryMarshalEx.cs index 76eb65d3..ef4f1db2 100644 --- a/src/MemoryPack.Core/Internal/MemoryMarshalEx.cs +++ b/src/MemoryPack.Core/Internal/MemoryMarshalEx.cs @@ -1,4 +1,4 @@ -#if !NET7_0_OR_GREATER +#if NETSTANDARD using System.Runtime.CompilerServices; using System.Runtime.InteropServices; diff --git a/src/MemoryPack.Core/Internal/ReusableLinkedArrayBufferWriter.cs b/src/MemoryPack.Core/Internal/ReusableLinkedArrayBufferWriter.cs index fed0670b..76ff4a31 100644 --- a/src/MemoryPack.Core/Internal/ReusableLinkedArrayBufferWriter.cs +++ b/src/MemoryPack.Core/Internal/ReusableLinkedArrayBufferWriter.cs @@ -6,7 +6,7 @@ namespace MemoryPack.Internal; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using static GC; using static MemoryMarshal; #else @@ -142,7 +142,7 @@ public byte[] ToArrayAndReset() if (buffers.Count > 0) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD foreach (ref var item in CollectionsMarshal.AsSpan(buffers)) #else foreach (var item in buffers) @@ -165,7 +165,7 @@ public byte[] ToArrayAndReset() } public void WriteToAndReset(ref MemoryPackWriter writer) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -182,7 +182,7 @@ public void WriteToAndReset(ref MemoryPackWriter w if (buffers.Count > 0) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD foreach (ref var item in CollectionsMarshal.AsSpan(buffers)) #else foreach (var item in buffers) @@ -253,7 +253,7 @@ void ResetCore() public void Reset() { if (totalWritten == 0) return; -#if NET7_0_OR_GREATER +#if !NETSTANDARD foreach (ref var item in CollectionsMarshal.AsSpan(buffers)) #else foreach (var item in buffers) diff --git a/src/MemoryPack.Core/Internal/ReusableReadOnlySequenceBuilder.cs b/src/MemoryPack.Core/Internal/ReusableReadOnlySequenceBuilder.cs index c563a296..0a11de59 100644 --- a/src/MemoryPack.Core/Internal/ReusableReadOnlySequenceBuilder.cs +++ b/src/MemoryPack.Core/Internal/ReusableReadOnlySequenceBuilder.cs @@ -70,7 +70,7 @@ public ReadOnlySequence Build() } long running = 0; -#if NET7_0_OR_GREATER +#if !NETSTANDARD var span = CollectionsMarshal.AsSpan(list); for (int i = 0; i < span.Length; i++) { @@ -96,7 +96,7 @@ public ReadOnlySequence Build() public void Reset() { -#if NET7_0_OR_GREATER +#if !NETSTANDARD var span = CollectionsMarshal.AsSpan(list); #else var span = list; diff --git a/src/MemoryPack.Core/Internal/TypeHelpers.cs b/src/MemoryPack.Core/Internal/TypeHelpers.cs index e40afeb4..42e24ed9 100644 --- a/src/MemoryPack.Core/Internal/TypeHelpers.cs +++ b/src/MemoryPack.Core/Internal/TypeHelpers.cs @@ -71,7 +71,7 @@ static Cache() UnmanagedSZArrayElementSize = (int)unsafeSizeOf.MakeGenericMethod(elementType!).Invoke(null, null)!; } } -#if NET7_0_OR_GREATER +#if !NETSTANDARD else { if (typeof(IFixedSizeMemoryPackable).IsAssignableFrom(type)) diff --git a/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.cs b/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.cs index 61e7b4a6..d5d539a0 100644 --- a/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.cs +++ b/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.cs @@ -97,7 +97,7 @@ internal static void RegisterWellKnownTypesFormatters() Register(new UnmanagedFormatter()); Register(new UnmanagedArrayFormatter()); Register(new NullableFormatter()); -#if NET7_0_OR_GREATER +#if !NETSTANDARD Register(new UnmanagedFormatter()); Register(new UnmanagedArrayFormatter()); Register(new NullableFormatter()); diff --git a/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.tt b/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.tt index 63fd2bc6..e27547ba 100644 --- a/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.tt +++ b/src/MemoryPack.Core/MemoryPackFormatterProvider.WellknownTypes.tt @@ -93,7 +93,7 @@ public static partial class MemoryPackFormatterProvider Register(new UnmanagedArrayFormatter<<#= item #>>()); Register(new NullableFormatter<<#= item #>>()); <# } #> -#if NET7_0_OR_GREATER +#if !NETSTANDARD <# foreach(var item in net7UnmanagedTypeNames) { #> Register(new UnmanagedFormatter<<#= item #>>()); Register(new UnmanagedArrayFormatter<<#= item #>>()); diff --git a/src/MemoryPack.Core/MemoryPackFormatterProvider.cs b/src/MemoryPack.Core/MemoryPackFormatterProvider.cs index cc762251..568bacab 100644 --- a/src/MemoryPack.Core/MemoryPackFormatterProvider.cs +++ b/src/MemoryPack.Core/MemoryPackFormatterProvider.cs @@ -51,7 +51,7 @@ public static void Register(MemoryPackFormatter formatter) Cache.formatter = formatter; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD public static void Register() where T : IMemoryPackFormatterRegister @@ -301,7 +301,7 @@ static Cache() if (formatterType != null) goto CREATE; #endif -#if NET8_0_OR_GREATER +#if !NETSTANDARD formatterType = TryCreateGenericFormatterType(type, FrozenCollectionFormatters); if (formatterType != null) goto CREATE; #endif @@ -372,7 +372,7 @@ public ErrorMemoryPackFormatter(Type type, string message) } public void Serialize(ref MemoryPackWriter writer, scoped ref object? value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter diff --git a/src/MemoryPack.Core/MemoryPackReader.cs b/src/MemoryPack.Core/MemoryPackReader.cs index e3e43c0d..79ef3ed1 100644 --- a/src/MemoryPack.Core/MemoryPackReader.cs +++ b/src/MemoryPack.Core/MemoryPackReader.cs @@ -2,13 +2,13 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using System.Text.Unicode; #endif namespace MemoryPack; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using static GC; using static MemoryMarshal; #else @@ -20,7 +20,7 @@ public ref partial struct MemoryPackReader { ReadOnlySequence bufferSource; readonly long totalLength; -#if NET7_0_OR_GREATER +#if !NETSTANDARD ref byte bufferReference; #else ReadOnlySpan bufferReference; @@ -40,7 +40,7 @@ public MemoryPackReader(in ReadOnlySequence sequence, MemoryPackReaderOpti { this.bufferSource = sequence.IsSingleSegment ? ReadOnlySequence.Empty : sequence; var span = sequence.FirstSpan; -#if NET7_0_OR_GREATER +#if !NETSTANDARD this.bufferReference = ref MemoryMarshal.GetReference(span); #else this.bufferReference = span; @@ -56,7 +56,7 @@ public MemoryPackReader(in ReadOnlySequence sequence, MemoryPackReaderOpti public MemoryPackReader(ReadOnlySpan buffer, MemoryPackReaderOptionalState optionalState) { this.bufferSource = ReadOnlySequence.Empty; -#if NET7_0_OR_GREATER +#if !NETSTANDARD this.bufferReference = ref MemoryMarshal.GetReference(buffer); #else this.bufferReference = buffer; @@ -77,7 +77,7 @@ public ref byte GetSpanReference(int sizeHint) // compare as unsigned, negative sizeHint(comes from malformed data) never takes this path and is rejected in GetNextSpan. if ((uint)sizeHint <= (uint)bufferLength) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD return ref bufferReference; #else return ref MemoryMarshal.GetReference(bufferReference); @@ -121,7 +121,7 @@ ref byte GetNextSpan(int sizeHint) { if (sizeHint <= bufferSource.FirstSpan.Length) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref MemoryMarshal.GetReference(bufferSource.FirstSpan); bufferLength = bufferSource.FirstSpan.Length; return ref bufferReference; @@ -135,7 +135,7 @@ ref byte GetNextSpan(int sizeHint) rentBuffer = ArrayPool.Shared.Rent(sizeHint); bufferSource.Slice(0, sizeHint).CopyTo(rentBuffer); var span = rentBuffer.AsSpan(0, sizeHint); -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref MemoryMarshal.GetReference(span); bufferLength = span.Length; return ref bufferReference; @@ -147,7 +147,7 @@ ref byte GetNextSpan(int sizeHint) } MemoryPackSerializationException.ThrowSequenceReachedEnd(); -#if NET7_0_OR_GREATER +#if !NETSTANDARD return ref bufferReference; // dummy. #else return ref MemoryMarshal.GetReference(bufferReference); @@ -171,7 +171,7 @@ public void Advance(int count) } bufferLength = rest; -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref Unsafe.Add(ref bufferReference, count); #else bufferReference = bufferReference.Slice(count); @@ -195,7 +195,7 @@ bool TryAdvanceSequence(int count) } bufferSource = bufferSource.Slice(advancedCount + count); -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref MemoryMarshal.GetReference(bufferSource.FirstSpan); #else bufferReference = bufferSource.FirstSpan; @@ -211,7 +211,7 @@ public void GetRemainingSource(out ReadOnlySpan singleSource, out ReadOnly if (bufferSource.IsEmpty) { remainingSource = ReadOnlySequence.Empty; -#if NET7_0_OR_GREATER +#if !NETSTANDARD singleSource = MemoryMarshal.CreateReadOnlySpan(ref bufferReference, bufferLength); #else singleSource = bufferReference; @@ -433,7 +433,7 @@ string ReadUtf8(int utf8Length) } -#if NET7_0_OR_GREATER +#if !NETSTANDARD // regular path, know decoded UTF16 length will gets faster decode result unsafe { @@ -473,7 +473,7 @@ public T1 ReadUnmanaged() return value1; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD [MethodImpl(MethodImplOptions.AggressiveInlining)] public void ReadPackable(scoped ref T? value) @@ -644,7 +644,7 @@ public void ReadSpan(scoped ref Span value) public void ReadPackableArray(scoped ref T?[]? value) where T : IMemoryPackable { -#if !NET7_0_OR_GREATER +#if NETSTANDARD ReadArray(ref value); return; #else @@ -683,7 +683,7 @@ public void ReadPackableArray(scoped ref T?[]? value) public void ReadPackableSpan(scoped ref Span value) where T : IMemoryPackable { -#if !NET7_0_OR_GREATER +#if NETSTANDARD ReadSpan(ref value); return; #else @@ -864,7 +864,7 @@ public void ReadSpanWithoutReadLengthHeader(int length, scoped ref Span v public void ReadPackableSpanWithoutReadLengthHeader(int length, scoped ref Span value) where T : IMemoryPackable { -#if !NET7_0_OR_GREATER +#if NETSTANDARD ReadSpanWithoutReadLengthHeader(length, ref value); return; #else diff --git a/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs b/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs index 6325523e..65b98910 100644 --- a/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs +++ b/src/MemoryPack.Core/MemoryPackSerializer.Deserialize.cs @@ -12,7 +12,7 @@ public static partial class MemoryPackSerializer static MemoryPackReaderOptionalState? threadStaticReaderOptionalState; public static T? Deserialize< -#if NET5_0_OR_GREATER +#if !NETSTANDARD [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] #endif T>(ReadOnlySpan buffer, MemoryPackSerializerOptions? options = default) @@ -23,7 +23,7 @@ public static T? Deserialize< } public static int Deserialize< -#if NET5_0_OR_GREATER +#if !NETSTANDARD [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] #endif T>(ReadOnlySpan buffer, ref T? value, MemoryPackSerializerOptions? options = default) @@ -59,7 +59,7 @@ public static int Deserialize< } public static T? Deserialize< -#if NET5_0_OR_GREATER +#if !NETSTANDARD [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] #endif T>(in ReadOnlySequence buffer, MemoryPackSerializerOptions? options = default) @@ -70,7 +70,7 @@ public static T? Deserialize< } public static int Deserialize< -#if NET5_0_OR_GREATER +#if !NETSTANDARD [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] #endif T>(in ReadOnlySequence buffer, ref T? value, MemoryPackSerializerOptions? options = default) @@ -141,7 +141,7 @@ public static int Deserialize< } public static async ValueTask DeserializeAsync< -#if NET5_0_OR_GREATER +#if !NETSTANDARD [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] #endif T>(Stream stream, MemoryPackSerializerOptions? options = default, CancellationToken cancellationToken = default) diff --git a/src/MemoryPack.Core/MemoryPackSerializer.NonGenerics.cs b/src/MemoryPack.Core/MemoryPackSerializer.NonGenerics.cs index 5e226f9f..7fa33d5f 100644 --- a/src/MemoryPack.Core/MemoryPackSerializer.NonGenerics.cs +++ b/src/MemoryPack.Core/MemoryPackSerializer.NonGenerics.cs @@ -32,7 +32,7 @@ public static byte[] Serialize(Type type, object? value, MemoryPackSerializerOpt } public static unsafe void Serialize(Type type, in TBufferWriter bufferWriter, object? value, MemoryPackSerializerOptions? options = default) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -58,7 +58,7 @@ public static unsafe void Serialize(Type type, in TBufferWriter b [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Serialize(Type type, ref MemoryPackWriter writer, object? value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter diff --git a/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs b/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs index 73f1d3f7..c0c8a9bf 100644 --- a/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs +++ b/src/MemoryPack.Core/MemoryPackSerializer.Serialize.cs @@ -5,7 +5,7 @@ namespace MemoryPack; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using static MemoryMarshal; using static GC; #else @@ -27,7 +27,7 @@ public static byte[] Serialize(in T? value, MemoryPackSerializerOptions? opti Unsafe.WriteUnaligned(ref GetArrayDataReference(array), value); return array; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD var typeKind = TypeHelpers.TryGetUnmanagedSZArrayElementSizeOrMemoryPackableFixedSize(out var elementSize); if (typeKind == TypeHelpers.TypeKind.None) { @@ -86,7 +86,7 @@ public static byte[] Serialize(in T? value, MemoryPackSerializerOptions? opti } public static unsafe void Serialize(in TBufferWriter bufferWriter, in T? value, MemoryPackSerializerOptions? options = default) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -100,7 +100,7 @@ public static unsafe void Serialize(in TBufferWriter bufferWri bufferWriterRef.Advance(Unsafe.SizeOf()); return; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD var typeKind = TypeHelpers.TryGetUnmanagedSZArrayElementSizeOrMemoryPackableFixedSize(out var elementSize); if (typeKind == TypeHelpers.TypeKind.UnmanagedSZArray) { @@ -154,7 +154,7 @@ public static unsafe void Serialize(in TBufferWriter bufferWri [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Serialize(ref MemoryPackWriter writer, in T? value) -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter diff --git a/src/MemoryPack.Core/MemoryPackSerializerOptions.cs b/src/MemoryPack.Core/MemoryPackSerializerOptions.cs index 917483ea..00cfa3c9 100644 --- a/src/MemoryPack.Core/MemoryPackSerializerOptions.cs +++ b/src/MemoryPack.Core/MemoryPackSerializerOptions.cs @@ -19,7 +19,7 @@ public enum StringEncoding : byte } } -#if !NET5_0_OR_GREATER +#if NETSTANDARD namespace System.Runtime.CompilerServices { diff --git a/src/MemoryPack.Core/MemoryPackWriter.cs b/src/MemoryPack.Core/MemoryPackWriter.cs index 08f4a3ae..f024b01c 100644 --- a/src/MemoryPack.Core/MemoryPackWriter.cs +++ b/src/MemoryPack.Core/MemoryPackWriter.cs @@ -2,13 +2,13 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Text; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using System.Text.Unicode; #endif namespace MemoryPack; -#if NET7_0_OR_GREATER +#if !NETSTANDARD using static MemoryMarshal; #else using static MemoryPack.Internal.MemoryMarshalEx; @@ -16,7 +16,7 @@ namespace MemoryPack; [StructLayout(LayoutKind.Auto)] public ref partial struct MemoryPackWriter -#if NET7_0_OR_GREATER +#if !NETSTANDARD where TBufferWriter : IBufferWriter #else where TBufferWriter : class, IBufferWriter @@ -24,7 +24,7 @@ public ref partial struct MemoryPackWriter { const int DepthLimit = 1000; -#if NET7_0_OR_GREATER +#if !NETSTANDARD ref TBufferWriter bufferWriter; ref byte bufferReference; #else @@ -45,7 +45,7 @@ public ref partial struct MemoryPackWriter public MemoryPackWriter(ref TBufferWriter writer, MemoryPackWriterOptionalState optionalState) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD this.bufferWriter = ref writer; this.bufferReference = ref Unsafe.NullRef(); #else @@ -63,7 +63,7 @@ public MemoryPackWriter(ref TBufferWriter writer, MemoryPackWriterOptionalState // optimized ctor, avoid first GetSpan call if we can. public MemoryPackWriter(ref TBufferWriter writer, byte[] firstBufferOfWriter, MemoryPackWriterOptionalState optionalState) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD this.bufferWriter = ref writer; this.bufferReference = ref GetArrayDataReference(firstBufferOfWriter); #else @@ -80,7 +80,7 @@ public MemoryPackWriter(ref TBufferWriter writer, byte[] firstBufferOfWriter, Me public MemoryPackWriter(ref TBufferWriter writer, Span firstBufferOfWriter, MemoryPackWriterOptionalState optionalState) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD this.bufferWriter = ref writer; this.bufferReference = ref MemoryMarshal.GetReference(firstBufferOfWriter); #else @@ -103,7 +103,7 @@ public ref byte GetSpanReference(int sizeHint) RequestNewBuffer(sizeHint); } -#if NET7_0_OR_GREATER +#if !NETSTANDARD return ref bufferReference; #else return ref MemoryMarshal.GetReference(bufferReference); @@ -119,7 +119,7 @@ void RequestNewBuffer(int sizeHint) advancedCount = 0; } var span = bufferWriter.GetSpan(sizeHint); -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref MemoryMarshal.GetReference(span); #else bufferReference = span; @@ -139,7 +139,7 @@ public void Advance(int count) } bufferLength = rest; -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref Unsafe.Add(ref bufferReference, count); #else bufferReference = bufferReference.Slice(count); @@ -156,7 +156,7 @@ public void Flush() bufferWriter.Advance(advancedCount); advancedCount = 0; } -#if NET7_0_OR_GREATER +#if !NETSTANDARD bufferReference = ref Unsafe.NullRef(); #else bufferReference = default; @@ -305,7 +305,7 @@ public void WriteUtf16(string? value) ref var dest = ref GetSpanReference(copyByteCount + 4); Unsafe.WriteUnaligned(ref dest, value.Length); -#if NET7_0_OR_GREATER +#if !NETSTANDARD ref var src = ref Unsafe.As(ref Unsafe.AsRef(in value.GetPinnableReference())); Unsafe.CopyBlockUnaligned(ref Unsafe.Add(ref dest, 4), ref src, (uint)copyByteCount); #else @@ -360,7 +360,7 @@ public void WriteUtf8(string? value) Unsafe.WriteUnaligned(ref Unsafe.Add(ref destPointer, 4), source.Length); var dest = MemoryMarshal.CreateSpan(ref Unsafe.Add(ref destPointer, 8), maxByteCount); -#if NET7_0_OR_GREATER +#if !NETSTANDARD var status = Utf8.FromUtf16(source, dest, out var _, out var bytesWritten, replaceInvalidSequences: false); if (status != OperationStatus.Done) { @@ -397,7 +397,7 @@ public void WriteUtf8(ReadOnlySpan utf8Value, int utf16Length = -1) Advance(utf8Value.Length + 8); } -#if NET7_0_OR_GREATER +#if !NETSTANDARD [MethodImpl(MethodImplOptions.AggressiveInlining)] public void WritePackable(scoped in T? value) @@ -511,7 +511,7 @@ public void WriteSpan(scoped ReadOnlySpan value) public void WritePackableArray(T?[]? value) where T : IMemoryPackable { -#if !NET7_0_OR_GREATER +#if NETSTANDARD WriteArray(value); return; #else @@ -540,7 +540,7 @@ public void WritePackableArray(T?[]? value) public void WritePackableSpan(scoped Span value) where T : IMemoryPackable { -#if !NET7_0_OR_GREATER +#if NETSTANDARD WriteSpan(value); return; #else @@ -562,7 +562,7 @@ public void WritePackableSpan(scoped Span value) public void WritePackableSpan(scoped ReadOnlySpan value) where T : IMemoryPackable { -#if !NET7_0_OR_GREATER +#if NETSTANDARD WriteSpan(value); return; #else diff --git a/src/MemoryPack.Core/MemoryPackWriterOptionalState.cs b/src/MemoryPack.Core/MemoryPackWriterOptionalState.cs index 2c13cb82..e9b66fd4 100644 --- a/src/MemoryPack.Core/MemoryPackWriterOptionalState.cs +++ b/src/MemoryPack.Core/MemoryPackWriterOptionalState.cs @@ -64,7 +64,7 @@ public void Reset() public (bool existsReference, uint id) GetOrAddReference(object value) { -#if NET7_0_OR_GREATER +#if !NETSTANDARD ref var id = ref CollectionsMarshal.GetValueRefOrAddDefault(objectToRef, value, out var exists); if (exists) { From 824dc4350c7b999170d40fd2b906840b0abd2dcc Mon Sep 17 00:00:00 2001 From: aetos Date: Thu, 12 Nov 2026 17:19:31 +0900 Subject: [PATCH 5/7] chore: remove the Net6VsNet7 and SandboxNet6 sandboxes They target net6.0 and net7.0, which are out of support. Net6VsNet7 compared the .NET 6 and .NET 7 runtimes. Co-Authored-By: Claude Opus 5.5 --- MemoryPack.sln | 18 --- sandbox/Net6VsNet7/Net6VsNet7.csproj | 26 --- sandbox/Net6VsNet7/Program.cs | 98 ----------- sandbox/SandboxNet6/NamespaceTest.cs | 16 -- sandbox/SandboxNet6/Program.cs | 215 ------------------------- sandbox/SandboxNet6/SandboxNet6.csproj | 26 --- 6 files changed, 399 deletions(-) delete mode 100644 sandbox/Net6VsNet7/Net6VsNet7.csproj delete mode 100644 sandbox/Net6VsNet7/Program.cs delete mode 100644 sandbox/SandboxNet6/NamespaceTest.cs delete mode 100644 sandbox/SandboxNet6/Program.cs delete mode 100644 sandbox/SandboxNet6/SandboxNet6.csproj diff --git a/MemoryPack.sln b/MemoryPack.sln index 08550d3f..095ce912 100644 --- a/MemoryPack.sln +++ b/MemoryPack.sln @@ -27,14 +27,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SandboxWebApp", "sandbox\Sa EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.AspNetCoreMvcFormatter", "src\MemoryPack.AspNetCoreMvcFormatter\MemoryPack.AspNetCoreMvcFormatter.csproj", "{64B20612-4990-40C7-8191-E2A033CD1EF5}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SandboxNet6", "sandbox\SandboxNet6\SandboxNet6.csproj", "{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary", "sandbox\ClassLibrary\ClassLibrary.csproj", "{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeAot", "sandbox\NativeAot\NativeAot.csproj", "{6E18AECF-34B2-48F9-9694-54150FB156EB}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Net6VsNet7", "sandbox\Net6VsNet7\Net6VsNet7.csproj", "{5612B811-586A-4EB3-9AE7-60CAD4969A1B}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.UnityShims", "src\MemoryPack.UnityShims\MemoryPack.UnityShims.csproj", "{9339C66C-25E5-4130-A213-9BA1804AD562}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Tests.NetStandard", "tests\MemoryPack.Tests.NetStandard\MemoryPack.Tests.NetStandard.csproj", "{B498EF75-D4BB-4B60-B15D-A9DD4059275A}" @@ -100,12 +96,6 @@ Global {64B20612-4990-40C7-8191-E2A033CD1EF5}.Release|Any CPU.Build.0 = Release|Any CPU {64B20612-4990-40C7-8191-E2A033CD1EF5}.WinBenchmark|Any CPU.ActiveCfg = Release|Any CPU {64B20612-4990-40C7-8191-E2A033CD1EF5}.WinBenchmark|Any CPU.Build.0 = Release|Any CPU - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.Release|Any CPU.Build.0 = Release|Any CPU - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.WinBenchmark|Any CPU.ActiveCfg = Release|Any CPU - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.WinBenchmark|Any CPU.Build.0 = Release|Any CPU {0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -118,12 +108,6 @@ Global {6E18AECF-34B2-48F9-9694-54150FB156EB}.Release|Any CPU.Build.0 = Release|Any CPU {6E18AECF-34B2-48F9-9694-54150FB156EB}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU {6E18AECF-34B2-48F9-9694-54150FB156EB}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU - {5612B811-586A-4EB3-9AE7-60CAD4969A1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5612B811-586A-4EB3-9AE7-60CAD4969A1B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5612B811-586A-4EB3-9AE7-60CAD4969A1B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5612B811-586A-4EB3-9AE7-60CAD4969A1B}.Release|Any CPU.Build.0 = Release|Any CPU - {5612B811-586A-4EB3-9AE7-60CAD4969A1B}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU - {5612B811-586A-4EB3-9AE7-60CAD4969A1B}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU {9339C66C-25E5-4130-A213-9BA1804AD562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9339C66C-25E5-4130-A213-9BA1804AD562}.Debug|Any CPU.Build.0 = Debug|Any CPU {9339C66C-25E5-4130-A213-9BA1804AD562}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -150,10 +134,8 @@ Global {31F067EA-3E16-47DD-A6E6-9AFDDD82E22F} = {796FB992-A35C-405B-82A7-4C90C5673174} {F9D66CB1-8D28-426B-BB12-C9F5D30EC6A0} = {796FB992-A35C-405B-82A7-4C90C5673174} {64B20612-4990-40C7-8191-E2A033CD1EF5} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF} - {87C0CEAA-E511-46AA-93AB-AF742A1F8EE2} = {796FB992-A35C-405B-82A7-4C90C5673174} {0ADCE3AF-C900-4FCB-938B-654211EDD6BE} = {796FB992-A35C-405B-82A7-4C90C5673174} {6E18AECF-34B2-48F9-9694-54150FB156EB} = {796FB992-A35C-405B-82A7-4C90C5673174} - {5612B811-586A-4EB3-9AE7-60CAD4969A1B} = {796FB992-A35C-405B-82A7-4C90C5673174} {9339C66C-25E5-4130-A213-9BA1804AD562} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF} {B498EF75-D4BB-4B60-B15D-A9DD4059275A} ={204004F9-9B91-4DD1-812C-80D629169ED5} EndGlobalSection diff --git a/sandbox/Net6VsNet7/Net6VsNet7.csproj b/sandbox/Net6VsNet7/Net6VsNet7.csproj deleted file mode 100644 index 5192502b..00000000 --- a/sandbox/Net6VsNet7/Net6VsNet7.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - Exe - net7.0;net6.0 - enable - enable - - - - - - - - - - - Analyzer - false - - - - - - - diff --git a/sandbox/Net6VsNet7/Program.cs b/sandbox/Net6VsNet7/Program.cs deleted file mode 100644 index c912d561..00000000 --- a/sandbox/Net6VsNet7/Program.cs +++ /dev/null @@ -1,98 +0,0 @@ -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Configs; -using BenchmarkDotNet.Diagnosers; -using BenchmarkDotNet.Environments; -using BenchmarkDotNet.Exporters; -using BenchmarkDotNet.Jobs; -using BenchmarkDotNet.Running; -using MemoryPack; -using System.Buffers; -using System.Reflection; - -var config = ManualConfig.CreateMinimumViable() - .AddDiagnoser(MemoryDiagnoser.Default) - // .AddColumn(StatisticColumn.OperationsPerSecond) - //.AddExporter(DefaultExporters.Plain) - .AddExporter(MarkdownExporter.Default) - .AddJob(Job.Default.WithWarmupCount(1).WithIterationCount(1).WithRuntime(CoreRuntime.Core60)) - .AddJob(Job.Default.WithWarmupCount(1).WithIterationCount(1).WithRuntime(CoreRuntime.Core70)); - -#if DEBUG - -#else -BenchmarkSwitcher.FromTypes(new[] { typeof(Net6Net7<>) }).RunAllJoined(config); -#endif - -[GenericTypeArguments(typeof(Sample))] -// [GenericTypeArguments(typeof(Sample2))] -[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByMethod)] -public class Net6Net7 - where T : class, new() -{ - private T s; - byte[] bin; - - public Net6Net7() - { - s = new(); - bin = MemoryPackSerializer.Serialize(s); - } - - //[Benchmark] - //public void SerializeDeserialize() - //{ - // MemoryPackSerializer.Deserialize(MemoryPackSerializer.Serialize(s)); - //} - - [Benchmark] - public byte[] Serialize() - { - return MemoryPackSerializer.Serialize(s); - } - - [Benchmark] - public T? Deserialize() - { - return MemoryPackSerializer.Deserialize(bin); - } -} - -[MemoryPackable] -public partial class Sample -{ - public int PublicField; - // public readonly int PublicReadOnlyField; - public int PublicProperty { get; set; } - public int PrivateSetPublicProperty { get; private set; } - public int ReadOnlyPublicProperty { get; } - public int InitProperty { get; init; } - - [MemoryPackIgnore] - public int PublicProperty2 => PublicProperty + PublicField; - - [MemoryPackInclude] - int privateField2; - [MemoryPackInclude] - int privateProperty2 { get; set; } -} - -[MemoryPackable] -public partial class Sample2 -{ - public int PublicField; - // public readonly int PublicReadOnlyField; - public int PublicProperty { get; set; } - public int PrivateSetPublicProperty { get; private set; } - public int ReadOnlyPublicProperty { get; } - public int InitProperty { get; init; } - - public int[]? ArrayProp { get; set; } - - [MemoryPackIgnore] - public int PublicProperty2 => PublicProperty + PublicField; - - [MemoryPackInclude] - int privateField2; - [MemoryPackInclude] - int privateProperty2 { get; set; } -} diff --git a/sandbox/SandboxNet6/NamespaceTest.cs b/sandbox/SandboxNet6/NamespaceTest.cs deleted file mode 100644 index 609d2b0f..00000000 --- a/sandbox/SandboxNet6/NamespaceTest.cs +++ /dev/null @@ -1,16 +0,0 @@ -using MemoryPack; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SandboxNet6 -{ - [MemoryPackable] - public partial class NamespaceTest - { - public int MyProperty { get; set; } - } - -} diff --git a/sandbox/SandboxNet6/Program.cs b/sandbox/SandboxNet6/Program.cs deleted file mode 100644 index 670b814d..00000000 --- a/sandbox/SandboxNet6/Program.cs +++ /dev/null @@ -1,215 +0,0 @@ -// See https://aka.ms/new-console-template for more information -using MemoryPack; -using System.Buffers; -using System.Drawing; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - - -// System.Buffers.IBufferWriter -Console.WriteLine("Hello, World!"); - - -[MemoryPackable(GenerateType.NoGenerate)] -public partial interface IForExternalUnion -{ - public int BaseValue { get; set; } -} - -[MemoryPackable] -public partial class AForOne : IForExternalUnion -{ - public int BaseValue { get; set; } - public int MyProperty { get; set; } -} - -[MemoryPackable] -public partial class AForTwo : IForExternalUnion -{ - public int BaseValue { get; set; } - public int MyProperty { get; set; } -} - -[MemoryPackUnionFormatter(typeof(IForExternalUnion))] -[MemoryPackUnion(0, typeof(AForOne))] -[MemoryPackUnion(1, typeof(AForTwo))] -public partial class ForExternalUnionFormatter -{ -} - - -[MemoryPackable] -public partial class HelloMemoryPackable -{ - public int MyProperty { get; set; } -} - - -[MemoryPackable] -public partial class HelloMemoryPackable2 -{ - public HelloMemoryPackable? MyProperty { get; set; } - // public TypeAccessException My3Property { get; set; } -} - - -[MemoryPackable] -[MemoryPackUnion(0, typeof(FooClass))] -[MemoryPackUnion(249, typeof(BarClass))] -public partial interface IUnionSample -{ -} - -[MemoryPackable] -public partial class FooClass : IUnionSample -{ - public int XYZ { get; set; } -} - -[MemoryPackable] -public partial class BarClass : IUnionSample -{ - public string? OPQ { get; set; } -} - - -[MemoryPackable] -public partial struct IncludesReferenceStruct -{ - public int X; - public string? Y; -} - - -[MemoryPackable] -[MemoryPackUnion(0, typeof(GenricUnionA<>))] -[MemoryPackUnion(1, typeof(GenricUnionB<>))] -public partial interface IGenericUnion -{ - ToaruHoge? Value { get; set; } -} - - -[MemoryPackable] -public partial class GenricUnionA : IGenericUnion -{ - public T? Value { get; set; } - public int MyProperty { get; set; } -} - -[MemoryPackable] -public partial class GenricUnionB : IGenericUnion -{ - public T? Value { get; set; } - public double MyProperty { get; set; } -} - - -[MemoryPackable] -public partial struct PartialStructOne -{ - public int X; - public int Y; - - //[MemoryPackConstructor] - public PartialStructOne(int x) - { - this.X = x; - this.Y = 0; - } - - //[MemoryPackConstructor] - public PartialStructOne(int x, int y) - { - this.X = x; - this.Y = y; - } -} - -//[MemoryPackable] -//public partial struct DateTimeParamDefault -//{ -// public DateTimeOffset DateTime; // short offset(2+padding) + dateTime/ulong(8) = 16 -// public long Timestamp; // 8 -// public bool IsItInSeconds; // 1(+padding7) = 8 -//} - -//[StructLayout(LayoutKind.Sequential)] -//[MemoryPackable] -//public partial struct TesTest -//{ -// public ValueTuple VTI; -// public MyMessageHeader MyMsgHead; -// public bool IsItInSeconds; // 1(+padding7) = 8 -//} - -//[StructLayout(LayoutKind.Sequential)] -//[MemoryPackable] -//public partial struct DateTimeParamSequential -//{ -// public DateTimeOffset DateTime; // short offset(2+padding) + dateTime/ulong(8) = 16 -// public long Timestamp; // 8 -// public bool IsItInSeconds; // 1(+padding7) = 8 -//} - -//[StructLayout(LayoutKind.Auto)] -//[MemoryPackable] -//public partial struct DateTimeParamAuto -//{ -// public DateTimeOffset DateTime; // short offset(2+padding) + dateTime/ulong(8) = 16 -// public long Timestamp; // 8 -// public bool IsItInSeconds; // 1(+padding7) = 8 -//} - -//[StructLayout(LayoutKind.Explicit, Size = 25)] -//[MemoryPackable] -//public partial struct DateTimeParamExplicit -//{ -// [FieldOffset(9)] -// public DateTimeOffset DateTime; -// [FieldOffset(1)] -// public long Timestamp; // 8 -// [FieldOffset(0)] -// public bool IsItInSeconds; // 1 -//} - -//[StructLayout(LayoutKind.Auto)] -//public struct MyMessageHeader -//{ -//} - - -public struct float2 { } -public struct quaternion { } - -[Serializable] -[MemoryPackable] -public partial class PlayerInput -{ - public float2 move; - public quaternion target; - public List keyRecords = new(); -} - -public enum EAction : byte -{ - Ability1, - Ability2, - Ability3, - Ability4, - Ability5, - Ability6, -} - -public enum EActionStatus : byte -{ - KeyDown = 0, - keyPressing = 1, - KeyUp = 2, -} - -public struct KeyRecord -{ - public EAction action; - public EActionStatus status; -} diff --git a/sandbox/SandboxNet6/SandboxNet6.csproj b/sandbox/SandboxNet6/SandboxNet6.csproj deleted file mode 100644 index caae53d2..00000000 --- a/sandbox/SandboxNet6/SandboxNet6.csproj +++ /dev/null @@ -1,26 +0,0 @@ - - - - Exe - net6.0 - enable - 10.0 - enable - - - - - - Analyzer - false - - - - - - From cffb17128c943fb456a57d5d97e23c4b079ae880 Mon Sep 17 00:00:00 2001 From: aetos Date: Thu, 12 Nov 2026 17:19:32 +0900 Subject: [PATCH 6/7] docs: update README for net8.0 and net10.0 - Recommend .NET 10 instead of .NET 7. - Target framework dependency: library authors should multi-target netstandard2.1 and net8.0 instead of net7.0. - Remove the note about the .NET 7 Native AOT crash, which was fixed in .NET 8. Co-Authored-By: Claude Opus 5.5 --- README.md | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e675a201..5af1dc0d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Other than performance, MemoryPack has these features. Installation --- -This library is distributed via NuGet. For best performance, recommend to use `.NET 7`. Minimum requirement is `.NET Standard 2.1`. +This library is distributed via NuGet. For best performance, recommend to use `.NET 10`. Minimum requirement is `.NET Standard 2.1`. > PM> Install-Package [MemoryPack](https://www.nuget.org/packages/MemoryPack) @@ -1379,16 +1379,16 @@ using (var state = MemoryPackReaderOptionalStatePool.Rent(MemoryPackSerializerOp Target framework dependency --- -MemoryPack provides `netstandard2.1` and `net7.0` but both are not compatible. For example, MemoryPackable types under `netstandard2.1` project and use it from `net7.0` project, throws runtime exception like this +MemoryPack provides `netstandard2.1`, `net8.0` and `net10.0`, but the `netstandard2.1` build is not compatible with the `net8.0` and `net10.0` builds. For example, MemoryPackable types under `netstandard2.1` project and use it from `net8.0` project, throws runtime exception like this > Unhandled exception. System.TypeLoadException: Virtual static method '*' is not implemented on type '*' from assembly '*'. -Since net7.0 uses static abstract members (`Virtual static method`), that does not support netstandard2.1, this behavior is a specification. +Since net8.0 and net10.0 use static abstract members (`Virtual static method`), that does not support netstandard2.1, this behavior is a specification. Applications on .NET 7 or lower use the netstandard2.1 build. -.NET 7 project shouldn't use the netstandard 2.1 dll. In other words, if the Application is a .NET 7 Project, all the dependencies that use MemoryPack must support .NET 7. So if a library developer has a dependency on MemoryPack, you need to configure dual target framework. +.NET 8 or later project shouldn't use the netstandard 2.1 dll. In other words, if the Application is a .NET 8 or later Project, all the dependencies that use MemoryPack must support .NET 8 or later. So if a library developer has a dependency on MemoryPack, you need to configure dual target framework. ```xml -netstandard2.1;net7.0 +netstandard2.1;net8.0 ``` RPC @@ -1448,11 +1448,6 @@ The `MemoryPack.UnityShims` package provides shims for Unity's standard structs - Currently, the simple solution is to not use these types. For `DateTimeOffset`, you can use `Net10DateTimeOffset` or `UnityDateTimeOffset` instead, see [DateTimeOffset, Net10DateTimeOffset and UnityDateTimeOffset](#datetimeoffset-net10datetimeoffset-and-unitydatetimeoffset). -Native AOT ---- -Unfortunately, .NET 7 Native AOT causes crash (`Generic virtual method pointer lookup failure`) when use MemoryPack due to a runtime bug. It -is going to be fixed in .NET 8. Using ``Microsoft.DotNet.ILCompiler` preview version, will fix it in .NET 7. Please see [issue's comment](https://github.com/Cysharp/MemoryPack/issues/75#issuecomment-1386884611) how setup it. - Binary wire format specification --- The type of `T` defined in `Serialize` and `Deserialize` is called C# schema. MemoryPack format is not self-described format. Deserialize requires the corresponding C# schema. These types exist as internal representations of binaries, but types cannot be determined without a C# schema. From 851ab93cdcdbf60bc426b8bdea006c0155c20da6 Mon Sep 17 00:00:00 2001 From: aetos Date: Thu, 12 Nov 2026 20:11:26 +0900 Subject: [PATCH 7/7] test: use a unique output directory for the TypeScript generator tests The tests of each target framework run in parallel with the .NET 9 SDK or later, and the TypeScript generator tests wrote the same files (such as FullName.ts and MemoryPackWriter.ts) into the temp directory. Each TypeScriptOptionProvider now creates its own directory with Directory.CreateTempSubdirectory and deletes it when disposed. Co-Authored-By: Claude Opus 5.5 --- .../GeneratorDiagnosticsTest.TypeScript.cs | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/MemoryPack.Tests/SourceGeneratorTests/GeneratorDiagnosticsTest.TypeScript.cs b/tests/MemoryPack.Tests/SourceGeneratorTests/GeneratorDiagnosticsTest.TypeScript.cs index 75226673..20244f8d 100644 --- a/tests/MemoryPack.Tests/SourceGeneratorTests/GeneratorDiagnosticsTest.TypeScript.cs +++ b/tests/MemoryPack.Tests/SourceGeneratorTests/GeneratorDiagnosticsTest.TypeScript.cs @@ -21,7 +21,8 @@ public partial class GeneratorDiagnosticsTest { void Compile2(int id, string code, bool allowMultipleError = false) { - var (_, diagnostics) = CSharpGeneratorRunner.RunGenerator(code, options: new TypeScriptOptionProvider()); + using var optionProvider = new TypeScriptOptionProvider(); + var (_, diagnostics) = CSharpGeneratorRunner.RunGenerator(code, options: optionProvider); if (!allowMultipleError) { diagnostics.Length.Should().Be(1); @@ -35,15 +36,13 @@ void Compile2(int id, string code, bool allowMultipleError = false) string CompileAndRead(string code, string fileName, bool enableNullableTypes = true) { - var outputDir = Path.GetTempPath(); - var optionProvider = new TypeScriptOptionProvider(); + using var optionProvider = new TypeScriptOptionProvider(); - optionProvider["build_property.MemoryPackGenerator_TypeScriptOutputDirectory"] = outputDir; optionProvider["build_property.MemoryPackGenerator_TypeScriptEnableNullableTypes"] = enableNullableTypes ? "true" : "false"; CSharpGeneratorRunner.RunGenerator(code, options: optionProvider); - var outputFilePath = Path.Combine(outputDir, fileName); + var outputFilePath = Path.Combine(optionProvider.OutputDirectory, fileName); return File.ReadAllText(outputFilePath); } @@ -221,35 +220,51 @@ export class FullName { } - class TypeScriptOptionProvider : AnalyzerConfigOptionsProvider + // Each instance uses its own output directory, because the tests of each target framework run in parallel + // and the generator writes the same file names (such as MemoryPackWriter.ts) into the output directory. + class TypeScriptOptionProvider : AnalyzerConfigOptionsProvider, IDisposable { readonly Dictionary _values = new(); + public TypeScriptOptionProvider() + { + OutputDirectory = Directory.CreateTempSubdirectory("MemoryPack.Tests.").FullName; + } + + public string OutputDirectory { get; } + public string this[string key] { get => _values[key]; set => _values[key] = value; } - public override AnalyzerConfigOptions GlobalOptions => new SimpleOptions(_values); + public override AnalyzerConfigOptions GlobalOptions => new SimpleOptions(_values, OutputDirectory); public override AnalyzerConfigOptions GetOptions(SyntaxTree tree) { - return new SimpleOptions(_values); + return new SimpleOptions(_values, OutputDirectory); } public override AnalyzerConfigOptions GetOptions(AdditionalText textFile) { - return new SimpleOptions(_values); + return new SimpleOptions(_values, OutputDirectory); + } + + public void Dispose() + { + Directory.Delete(OutputDirectory, recursive: true); } public class SimpleOptions : AnalyzerConfigOptions { readonly Dictionary _configValues; + readonly string _outputDirectory; - public SimpleOptions(Dictionary configValues) + public SimpleOptions(Dictionary configValues, string outputDirectory) { _configValues = configValues; + _outputDirectory = outputDirectory; } /// @@ -266,7 +281,7 @@ public override bool TryGetValue(string key, [NotNullWhen(true)] out string? val if (key == "build_property.MemoryPackGenerator_TypeScriptOutputDirectory") { - value = Path.GetTempPath(); + value = _outputDirectory; return true; }