Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 378 #380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions src/MemoryPack.Generator/MemoryPackGenerator.Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void Emit(StringBuilder writer, IGeneratorContext context)
string staticRegisterFormatterMethod, staticMemoryPackableMethod, scopedRef, constraint, registerBody, registerT;
var fixedSizeInterface = "";
var fixedSizeMethod = "";
scopedRef = (context.IsCSharp11OrGreater())
scopedRef = context.IsNet7OrGreater && context.IsCSharp11OrGreater()
? "scoped ref"
: "ref";
if (!context.IsNet7OrGreater)
Expand All @@ -350,11 +350,7 @@ public void Emit(StringBuilder writer, IGeneratorContext context)
registerT = $"global::MemoryPack.MemoryPackFormatterProvider.Register<{TypeName}>();";

// similar as VersionTolerantOptimized but not includes String, Array
var fixedSize = false;
if (Members.All(x => x.Kind is MemberKind.Unmanaged or MemberKind.Enum or MemberKind.UnmanagedNullable or MemberKind.Blank))
{
fixedSize = true;
}
bool fixedSize = Members.All(x => x.Kind is MemberKind.Unmanaged or MemberKind.Enum or MemberKind.UnmanagedNullable or MemberKind.Blank);

var callbackCount = new[] { this.OnSerializing, this.OnSerialized, this.OnDeserialized, this.OnDeserializing }.Select(x => x.Length).Sum();
if (fixedSize && GenerateType == GenerateType.Object && !this.IsValueType && callbackCount == 0)
Expand Down Expand Up @@ -984,7 +980,7 @@ string EmitUnionTemplate(IGeneratorContext context)
var register = (context.IsNet7OrGreater)
? $"global::MemoryPack.MemoryPackFormatterProvider.Register<{TypeName}>();"
: "RegisterFormatter();";
var scopedRef = context.IsCSharp11OrGreater()
var scopedRef = context.IsNet7OrGreater && context.IsCSharp11OrGreater()
? "scoped ref"
: "ref";
string serializeMethodSignarture = context.IsForUnity
Expand Down Expand Up @@ -1045,7 +1041,7 @@ public override void Deserialize(ref MemoryPackReader reader, {{scopedRef}} {{Ty

public void EmitUnionFormatterTemplate(StringBuilder writer, IGeneratorContext context, INamedTypeSymbol formatterSymbol)
{
var scopedRef = context.IsCSharp11OrGreater()
var scopedRef = context.IsNet7OrGreater && context.IsCSharp11OrGreater()
? "scoped ref"
: "ref";
string serializeMethodSignarture = context.IsForUnity
Expand Down