diff --git a/Assets/Cryville/Common/Pdt/PdtInterpreter.cs b/Assets/Cryville/Common/Pdt/PdtInterpreter.cs index 52720e3..b7dbeb2 100644 --- a/Assets/Cryville/Common/Pdt/PdtInterpreter.cs +++ b/Assets/Cryville/Common/Pdt/PdtInterpreter.cs @@ -167,7 +167,7 @@ namespace Cryville.Common.Pdt { } object InterpretObject(Type type) { var result = ReflectionHelper.InvokeEmptyConstructor(type); - bool dictflag = ReflectionHelper.IsGenericDictionary(type); + bool dictflag = typeof(IDictionary).IsAssignableFrom(type); while (true) { try { ws(); } catch (IndexOutOfRangeException) { return result; } @@ -183,19 +183,20 @@ namespace Cryville.Common.Pdt { ((IDictionary)result).Add(key, value); } else { - MemberInfo prop; - bool flag = ReflectionHelper.TryFindMemberWithAttribute(type, out prop); - if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey); + MemberInfo prop = null; + bool flag = false; + if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey); + if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute(type, out prop); + if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey)); Type ptype = ReflectionHelper.GetMemberType(prop); - if (ReflectionHelper.IsGenericDictionary(ptype)) { + if (flag) { + if (!typeof(IDictionary).IsAssignableFrom(ptype)) + throw new InvalidOperationException("Internal error: Element list is not a dictionary"); var ktype = ptype.GetGenericArguments()[0]; var vtype = ptype.GetGenericArguments()[1]; - if (flag) { - object key = _binder.ChangeType(pkey, ktype, null); - object value = InterpretObject(vtype); - ((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value); - } - else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype)); + object key = _binder.ChangeType(pkey, ktype, null); + object value = InterpretObject(vtype); + ((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value); } else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype)); } @@ -211,21 +212,23 @@ namespace Cryville.Common.Pdt { ((IDictionary)result).Add(key, value); } else { - MemberInfo prop; - bool flag = ReflectionHelper.TryFindMemberWithAttribute(type, out prop); - if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey); + MemberInfo prop = null; + bool flag = false; + if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey); + if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute(type, out prop); + if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey)); var ptype = ReflectionHelper.GetMemberType(prop); - if (!typeof(IDictionary).IsAssignableFrom(ptype)) { - object value = _binder.ChangeType(exp, ptype, null); - ReflectionHelper.SetValue(prop, result, value, _binder); - } - else { + if (flag) { var ktype = ptype.GetGenericArguments()[0]; var vtype = ptype.GetGenericArguments()[1]; object key = _binder.ChangeType(pkey, ktype, null); object value = _binder.ChangeType(exp, vtype, null); ((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value); } + else { + object value = _binder.ChangeType(exp, ptype, null); + ReflectionHelper.SetValue(prop, result, value, _binder); + } } break; case '}':