Skip to content

Commit

Permalink
fix can't build netstandard2.1 lib on CSharp 11 #55
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Nov 18, 2022
1 parent adf6af2 commit 92143a6
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 18 deletions.
9 changes: 9 additions & 0 deletions MemoryPack.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Tests.Roslyn3",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Generator.Roslyn3", "src\MemoryPack.Generator.Roslyn3\MemoryPack.Generator.Roslyn3.csproj", "{0F57F162-9C68-4E0F-B89B-2EED31B69F38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary", "sandbox\ClassLibrary\ClassLibrary.csproj", "{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -122,6 +124,12 @@ Global
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Release|Any CPU.Build.0 = Release|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.WinBenchmark|Any CPU.Build.0 = Debug|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
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Release|Any CPU.Build.0 = Release|Any CPU
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -140,6 +148,7 @@ Global
{06384E50-13CE-4AA2-90B3-5EC116B06D01} = {C56A9A52-EE3A-44A5-A8EA-AE36C79FFB6C}
{E2C01D05-E7F1-4151-B536-90B138AF18EF} = {204004F9-9B91-4DD1-812C-80D629169ED5}
{0F57F162-9C68-4E0F-B89B-2EED31B69F38} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF}
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE} = {796FB992-A35C-405B-82A7-4C90C5673174}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01ADF7A3-0758-4A3C-9A18-AEF0F30B6E1B}
Expand Down
8 changes: 8 additions & 0 deletions sandbox/ClassLibrary/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

using MemoryPack;

[MemoryPackable]
public partial class Stat
{

}
19 changes: 19 additions & 0 deletions sandbox/ClassLibrary/ClassLibrary.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;netstandard2.1</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MemoryPack.Core\MemoryPack.Core.csproj" />
<ProjectReference Include="..\..\src\MemoryPack.Generator\MemoryPack.Generator.csproj">
<OutputItemType>Analyzer</OutputItemType>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/MemoryPack.Core/Internal/TypeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ static class Cache<T>
public static bool IsReferenceOrNullable;
public static bool IsUnmanagedSZArray;
public static int UnmanagedSZArrayElementSize;
public static bool IsFixedSizeMemoryPackable;
public static int MemoryPackableFixedSize;
public static bool IsFixedSizeMemoryPackable = false;
public static int MemoryPackableFixedSize = 0;

static Cache()
{
Expand Down
7 changes: 4 additions & 3 deletions src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,13 @@ public void Emit(StringBuilder writer, IGeneratorContext context)
string staticRegisterFormatterMethod, staticMemoryPackableMethod, scopedRef, constraint, registerBody, registerT;
var fixedSizeInterface = "";
var fixedSizeMethod = "";
scopedRef = (context.IsCSharp11OrGreater())
? "scoped ref"
: "ref";
if (!context.IsNet7OrGreater)
{
staticRegisterFormatterMethod = "public static void ";
staticMemoryPackableMethod = "public static void ";
scopedRef = "ref";
constraint = context.IsForUnity ? "" : "where TBufferWriter : class, System.Buffers.IBufferWriter<byte>";
registerBody = $"MemoryPackFormatterProvider.Register(new {Symbol.Name}Formatter());";
registerT = "RegisterFormatter();";
Expand All @@ -281,7 +283,6 @@ public void Emit(StringBuilder writer, IGeneratorContext context)
{
staticRegisterFormatterMethod = $"static void IMemoryPackFormatterRegister.";
staticMemoryPackableMethod = $"static void IMemoryPackable<{TypeName}>.";
scopedRef = "scoped ref";
constraint = "";
registerBody = $"MemoryPackFormatterProvider.Register(new MemoryPack.Formatters.MemoryPackableFormatter<{TypeName}>());";
registerT = $"MemoryPackFormatterProvider.Register<{TypeName}>();";
Expand Down Expand Up @@ -373,7 +374,7 @@ sealed class {{Symbol.Name}}Formatter : MemoryPackFormatter<{{TypeName}}>
}
[global::MemoryPack.Internal.Preserve]
public override void Deserialize(ref MemoryPackReader reader, ref {{TypeName}} value)
public override void Deserialize(ref MemoryPackReader reader, {{scopedRef}} {{TypeName}} value)
{
{{TypeName}}.Deserialize(ref reader, ref value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/MemoryPack.Generator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"MemoryPack.Generator": {
"commandName": "DebugRoslynComponent",
"targetProject": "..\\..\\sandbox\\SandboxConsoleApp\\SandboxConsoleApp.csproj"
"targetProject": "..\\..\\sandbox\\ClassLibrary\\ClassLibrary.csproj"
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ static class Cache<T>
public static bool IsReferenceOrNullable;
public static bool IsUnmanagedSZArray;
public static int UnmanagedSZArrayElementSize;
public static bool IsFixedSizeMemoryPackable;
public static int MemoryPackableFixedSize;
public static bool IsFixedSizeMemoryPackable = false;
public static int MemoryPackableFixedSize = 0;

static Cache()
{
Expand Down
Binary file not shown.
20 changes: 10 additions & 10 deletions src/MemoryPack.Unity/UserSettings/Layouts/default-2021.dwlt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MonoBehaviour:
width: 2336
height: 2061
m_ShowMode: 4
m_Title: Console
m_Title: Project
m_RootView: {fileID: 10}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
Expand Down Expand Up @@ -97,7 +97,7 @@ MonoBehaviour:
m_MinSize: {x: 310, y: 221}
m_MaxSize: {x: 4000, y: 4021}
vertical: 0
controlID: 108
controlID: 127
--- !u!114 &5
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -175,7 +175,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 300}
m_MaxSize: {x: 24288, y: 24288}
vertical: 0
controlID: 85
controlID: 86
--- !u!114 &8
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -324,7 +324,7 @@ MonoBehaviour:
m_MinSize: {x: 100, y: 300}
m_MaxSize: {x: 8096, y: 24288}
vertical: 1
controlID: 52
controlID: 87
--- !u!114 &14
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -427,8 +427,8 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 2776
y: 635
x: -32000
y: -31416
width: 1151
height: 882
m_ViewDataDictionary: {fileID: 0}
Expand All @@ -454,14 +454,14 @@ MonoBehaviour:
m_StartGridSize: 64
m_LastFolders: []
m_LastFoldersGridSize: -1
m_LastProjectPath: C:\Users\S04451\Documents\GitHub\MemoryPack\src\MemoryPack.Unity
m_LastProjectPath: C:\Users\owner\source\repos\MemoryPack\src\MemoryPack.Unity
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 38600000
m_LastClickedID: 24632
m_ExpandedIDs: 00000000f0600000
m_ExpandedIDs: 0000000066600000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -489,7 +489,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: ffffffff00000000f0600000
m_ExpandedIDs: ffffffff0000000066600000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down Expand Up @@ -619,7 +619,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: b2f5ffff04f6ffff4ef6ffffa0f7ffffb0f8ffff00fbffff
m_ExpandedIDs: 00fbffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
Expand Down

0 comments on commit 92143a6

Please sign in to comment.