From f232bf669920e70059b36bdcf2f48cef043a2442 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Wed, 25 Mar 2020 22:01:28 -0500 Subject: [PATCH] Added warning for implicitly converting to List --- .../GeneratedStoreImpl/Deserialization.cs | 28 +-------------- .../GeneratedStoreImpl/Serialization.cs | 1 + .../Stores/GeneratedStoreImpl/Utility.cs | 34 +++++++++++++++++-- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Deserialization.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Deserialization.cs index 772874b6..23856c70 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Deserialization.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Deserialization.cs @@ -18,33 +18,6 @@ namespace IPA.Config.Stores { internal static partial class GeneratedStoreImpl { - private static Type GetExpectedValueTypeForType(Type valT) - { - if (typeof(Value).IsAssignableFrom(valT)) // this is a Value subtype - return valT; - if (valT == typeof(string) - || valT == typeof(char)) return typeof(Text); - if (valT == typeof(bool)) return typeof(Boolean); - if (valT == typeof(byte) - || valT == typeof(sbyte) - || valT == typeof(short) - || valT == typeof(ushort) - || valT == typeof(int) - || valT == typeof(uint) - || valT == typeof(long) - || valT == typeof(IntPtr)) return typeof(Integer); - if (valT == typeof(float) - || valT == typeof(double) - || valT == typeof(decimal) - || valT == typeof(ulong) // ulong gets put into this, because decimal can hold it - || valT == typeof(UIntPtr)) return typeof(FloatingPoint); - if (typeof(IEnumerable).IsAssignableFrom(valT)) return typeof(List); - - // TODO: fill this out the rest of the way - - return typeof(Map); // default for various objects - } - private static void EmitDeserializeGeneratedValue(ILGenerator il, SerializedMemberInfo member, Type srcType, GetLocal GetLocal, Action thisarg, Action parentobj) { @@ -148,6 +121,7 @@ namespace IPA.Config.Stores } else { + Logger.config.Warn($"Implicit conversions to {expected} are not currently implemented"); il.Emit(OpCodes.Pop); il.Emit(OpCodes.Ldnull); } diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs index 23a5e1d8..81bfb3b0 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs @@ -113,6 +113,7 @@ namespace IPA.Config.Stores else if (targetType == typeof(List)) { // TODO: impl this (enumerables) + Logger.config.Warn($"Implicit conversions to {targetType} are not currently implemented"); il.Emit(OpCodes.Pop); il.Emit(OpCodes.Ldnull); } diff --git a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs index 10abdaa7..c4a2bea7 100644 --- a/IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs +++ b/IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs @@ -1,11 +1,14 @@ -using IPA.Logging; +using IPA.Config.Data; +using IPA.Logging; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; +using Boolean = IPA.Config.Data.Boolean; #if NET3 using Net3_Proxy; using Array = Net3_Proxy.Array; @@ -55,8 +58,6 @@ namespace IPA.Config.Stores private static void EmitLoad(ILGenerator il, SerializedMemberInfo member, Action thisarg) { - thisarg ??= il => il.Emit(OpCodes.Ldarg_0); - thisarg(il); // load this if (member.IsField) @@ -205,5 +206,32 @@ namespace IPA.Config.Stores parentobj(il); il.Emit(OpCodes.Call, method); } + + private static Type GetExpectedValueTypeForType(Type valT) + { + if (typeof(Value).IsAssignableFrom(valT)) // this is a Value subtype + return valT; + if (valT == typeof(string) + || valT == typeof(char)) return typeof(Text); + if (valT == typeof(bool)) return typeof(Boolean); + if (valT == typeof(byte) + || valT == typeof(sbyte) + || valT == typeof(short) + || valT == typeof(ushort) + || valT == typeof(int) + || valT == typeof(uint) + || valT == typeof(long) + || valT == typeof(IntPtr)) return typeof(Integer); + if (valT == typeof(float) + || valT == typeof(double) + || valT == typeof(decimal) + || valT == typeof(ulong) // ulong gets put into this, because decimal can hold it + || valT == typeof(UIntPtr)) return typeof(FloatingPoint); + if (typeof(IEnumerable).IsAssignableFrom(valT)) return typeof(List); + + // TODO: fill this out the rest of the way + + return typeof(Map); // default for various objects + } } }