object GetProperValue(BattleAgent ba, string properName) { Type t = ba.GetType(); PropertyInfo pi = t.GetProperty(properName); if (pi != null) { return(pi.GetValue(ba, null)); } else { FieldInfo fi = t.GetField(properName); if (fi != null) { return(fi.GetValue(ba)); } else { Debug.LogError("CONFIG ERROR: There is no property or field [ " + properName + " ] in class >" + t); return(null); } } }
void ChangeProperValue(BattleAgent target, string properName, object newValue) { Type t = target.GetType(); PropertyInfo pi = t.GetProperty(properName); if (pi != null) { oldValue = pi.GetValue(target, null); pi.SetValue(target, Convert.ChangeType(newValue, pi.PropertyType), null); } else { FieldInfo fi = t.GetField(properName); if (fi != null) { oldValue = fi.GetValue(target); fi.SetValue(target, Convert.ChangeType(newValue, fi.FieldType)); } else { Debug.LogError("CONFIG ERROR: There is no property or field [ " + properName + " ] in class >" + t); } } }