void AddListValue(TypeData listType, ref object list, int index, object value, bool canCreateInstance) { Type type = listType.Type; if (type.IsArray) { list = EnsureArrayIndex((Array)list, index, type.GetElementType()); listType.ConvertForAssignment(ref value); ((Array)list).SetValue(value, index); } else // Must be IEnumerable { if (list == null) { if (canCreateInstance) { list = CreateInstance(type, true); } else { throw CreateReadOnlyCollectionException(type.FullName); } } MethodInfo mi = type.GetMethod("Add", new Type[] { listType.ListItemType }); mi.Invoke(list, new object[] { value }); } }
public void SetValue(object ob, object value) { if (_member == null) { InitMember(ob.GetType()); } _typeData.ConvertForAssignment(ref value); if (_member is PropertyInfo) { ((PropertyInfo)_member).SetValue(ob, value, null); } else { ((FieldInfo)_member).SetValue(ob, value); } }