Browse Source

Fixed custom type field serialization in config system

pull/44/head
Anairkoen Schno 4 years ago
parent
commit
543d2b798f
2 changed files with 23 additions and 1 deletions
  1. +1
    -1
      IPA.Loader/Config/Providers/JsonConfigProvider.cs
  2. +22
    -0
      IPA.Loader/Config/Stores/GeneratedStoreImpl.cs

+ 1
- 1
IPA.Loader/Config/Providers/JsonConfigProvider.cs View File

@ -117,7 +117,7 @@ namespace IPA.Config.Providers
public void Store(Value value, FileInfo file)
{
if (file.Directory.Exists)
if (!file.Directory.Exists)
file.Directory.Create();
try


+ 22
- 0
IPA.Loader/Config/Stores/GeneratedStoreImpl.cs View File

@ -1604,6 +1604,28 @@ namespace IPA.Config.Stores
// for now, we assume that its a generated type implementing IGeneratedStore
var IGeneratedStore_Serialize = typeof(IGeneratedStore).GetMethod(nameof(IGeneratedStore.Serialize));
var IGeneratedStoreT_CopyFrom = typeof(IGeneratedStore<>).GetMethod(nameof(IGeneratedStore<int>.CopyFrom));
if (member.IsField)
{
var noCreate = il.DefineLabel();
var stlocal = GetLocal(member.Type);
// first check to make sure that this is an IGeneratedStore, because we don't control assignments to it
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Isinst, typeof(IGeneratedStore));
il.Emit(OpCodes.Brtrue_S, noCreate);
il.Emit(OpCodes.Stloc, stlocal);
EmitCreateChildGenerated(il, member.Type);
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Ldloc, stlocal);
il.Emit(OpCodes.Ldc_I4_0);
il.Emit(OpCodes.Callvirt, IGeneratedStoreT_CopyFrom);
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Stloc, stlocal);
EmitStore(il, member, il => il.Emit(OpCodes.Ldloc, stlocal));
il.MarkLabel(noCreate);
}
il.Emit(OpCodes.Callvirt, IGeneratedStore_Serialize);
}


Loading…
Cancel
Save