Browse Source

Added warning for implicitly converting to List

pull/44/head
Anairkoen Schno 4 years ago
parent
commit
677f120cb4
3 changed files with 33 additions and 30 deletions
  1. +1
    -27
      IPA.Loader/Config/Stores/GeneratedStoreImpl/Deserialization.cs
  2. +1
    -0
      IPA.Loader/Config/Stores/GeneratedStoreImpl/Serialization.cs
  3. +31
    -3
      IPA.Loader/Config/Stores/GeneratedStoreImpl/Utility.cs

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

@ -18,33 +18,6 @@ namespace IPA.Config.Stores
{ {
internal static partial class GeneratedStoreImpl 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, private static void EmitDeserializeGeneratedValue(ILGenerator il, SerializedMemberInfo member, Type srcType, GetLocal GetLocal,
Action<ILGenerator> thisarg, Action<ILGenerator> parentobj) Action<ILGenerator> thisarg, Action<ILGenerator> parentobj)
{ {
@ -148,6 +121,7 @@ namespace IPA.Config.Stores
} }
else else
{ {
Logger.config.Warn($"Implicit conversions to {expected} are not currently implemented");
il.Emit(OpCodes.Pop); il.Emit(OpCodes.Pop);
il.Emit(OpCodes.Ldnull); il.Emit(OpCodes.Ldnull);
} }


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

@ -113,6 +113,7 @@ namespace IPA.Config.Stores
else if (targetType == typeof(List)) else if (targetType == typeof(List))
{ {
// TODO: impl this (enumerables) // TODO: impl this (enumerables)
Logger.config.Warn($"Implicit conversions to {targetType} are not currently implemented");
il.Emit(OpCodes.Pop); il.Emit(OpCodes.Pop);
il.Emit(OpCodes.Ldnull); il.Emit(OpCodes.Ldnull);
} }


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

@ -1,11 +1,14 @@
using IPA.Logging;
using IPA.Config.Data;
using IPA.Logging;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Boolean = IPA.Config.Data.Boolean;
#if NET3 #if NET3
using Net3_Proxy; using Net3_Proxy;
using Array = Net3_Proxy.Array; using Array = Net3_Proxy.Array;
@ -55,8 +58,6 @@ namespace IPA.Config.Stores
private static void EmitLoad(ILGenerator il, SerializedMemberInfo member, Action<ILGenerator> thisarg) private static void EmitLoad(ILGenerator il, SerializedMemberInfo member, Action<ILGenerator> thisarg)
{ {
thisarg ??= il => il.Emit(OpCodes.Ldarg_0);
thisarg(il); // load this thisarg(il); // load this
if (member.IsField) if (member.IsField)
@ -205,5 +206,32 @@ namespace IPA.Config.Stores
parentobj(il); parentobj(il);
il.Emit(OpCodes.Call, method); 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
}
} }
} }

Loading…
Cancel
Save