Matches member name first then generic list in PDT.
This commit is contained in:
@@ -167,7 +167,7 @@ namespace Cryville.Common.Pdt {
|
|||||||
}
|
}
|
||||||
object InterpretObject(Type type) {
|
object InterpretObject(Type type) {
|
||||||
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
var result = ReflectionHelper.InvokeEmptyConstructor(type);
|
||||||
bool dictflag = ReflectionHelper.IsGenericDictionary(type);
|
bool dictflag = typeof(IDictionary).IsAssignableFrom(type);
|
||||||
while (true) {
|
while (true) {
|
||||||
try { ws(); }
|
try { ws(); }
|
||||||
catch (IndexOutOfRangeException) { return result; }
|
catch (IndexOutOfRangeException) { return result; }
|
||||||
@@ -183,19 +183,20 @@ namespace Cryville.Common.Pdt {
|
|||||||
((IDictionary)result).Add(key, value);
|
((IDictionary)result).Add(key, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MemberInfo prop;
|
MemberInfo prop = null;
|
||||||
bool flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
bool flag = false;
|
||||||
if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||||
|
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
|
||||||
|
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||||
Type ptype = ReflectionHelper.GetMemberType(prop);
|
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 ktype = ptype.GetGenericArguments()[0];
|
||||||
var vtype = ptype.GetGenericArguments()[1];
|
var vtype = ptype.GetGenericArguments()[1];
|
||||||
if (flag) {
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object value = InterpretObject(vtype);
|
||||||
object value = InterpretObject(vtype);
|
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
|
||||||
}
|
|
||||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
|
||||||
}
|
}
|
||||||
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
else ReflectionHelper.SetValue(prop, result, InterpretObject(ptype));
|
||||||
}
|
}
|
||||||
@@ -211,21 +212,23 @@ namespace Cryville.Common.Pdt {
|
|||||||
((IDictionary)result).Add(key, value);
|
((IDictionary)result).Add(key, value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
MemberInfo prop;
|
MemberInfo prop = null;
|
||||||
bool flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
bool flag = false;
|
||||||
if (!flag && pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
if (pkey is string) prop = ReflectionHelper.GetMember(type, (string)pkey);
|
||||||
|
if (prop == null) flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
|
||||||
|
if (prop == null) throw new MissingMemberException(string.Format("The property \"{0}\" is not found", pkey));
|
||||||
var ptype = ReflectionHelper.GetMemberType(prop);
|
var ptype = ReflectionHelper.GetMemberType(prop);
|
||||||
if (!typeof(IDictionary).IsAssignableFrom(ptype)) {
|
if (flag) {
|
||||||
object value = _binder.ChangeType(exp, ptype, null);
|
|
||||||
ReflectionHelper.SetValue(prop, result, value, _binder);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
var ktype = ptype.GetGenericArguments()[0];
|
var ktype = ptype.GetGenericArguments()[0];
|
||||||
var vtype = ptype.GetGenericArguments()[1];
|
var vtype = ptype.GetGenericArguments()[1];
|
||||||
object key = _binder.ChangeType(pkey, ktype, null);
|
object key = _binder.ChangeType(pkey, ktype, null);
|
||||||
object value = _binder.ChangeType(exp, vtype, null);
|
object value = _binder.ChangeType(exp, vtype, null);
|
||||||
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
((IDictionary)ReflectionHelper.GetValue(prop, result)).Add(key, value);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
object value = _binder.ChangeType(exp, ptype, null);
|
||||||
|
ReflectionHelper.SetValue(prop, result, value, _binder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '}':
|
case '}':
|
||||||
|
Reference in New Issue
Block a user