Browse Source

Fix serializing nullable value types

pull/74/head
Anairkoen Schno 2 years ago
parent
commit
31cbf4a3ea
Signed by: DaNike GPG Key ID: BEFB74D5F3FC4387
2 changed files with 13 additions and 2 deletions
  1. +12
    -1
      IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs
  2. +1
    -1
      IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs

+ 12
- 1
IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs View File

@ -23,6 +23,17 @@ namespace IPA.Config.Stores
{
EmitLoad(il, member, thisarg);
using var valueTypeLocal =
member.IsNullable
? GetLocal.Allocate(member.Type)
: default;
if (member.IsNullable)
{
il.Emit(OpCodes.Stloc, valueTypeLocal.Local);
il.Emit(OpCodes.Ldloca, valueTypeLocal.Local);
}
var endSerialize = il.DefineLabel();
if (member.AllowNull)
@ -48,7 +59,7 @@ namespace IPA.Config.Stores
var targetType = GetExpectedValueTypeForType(memberConversionType);
if (member.HasConverter)
{
using var stlocal = GetLocal.Allocate(member.Type);
using var stlocal = GetLocal.Allocate(memberConversionType);
using var valLocal = GetLocal.Allocate(typeof(Value));
il.Emit(OpCodes.Stloc, stlocal);


+ 1
- 1
IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs View File

@ -60,7 +60,7 @@ namespace IPA.Config.Stores
#endif
public static implicit operator LocalBuilder(AllocatedLocal loc) => loc.Local;
public void Dealloc() => allocator.Deallocate(this);
public void Dealloc() => allocator?.Deallocate(this);
public void Dispose() => Dealloc();
}


Loading…
Cancel
Save