public static void AddListByReflection(this FieldInfo fieldInfo, object obj) { var elementType = fieldInfo.FieldType.GetArrayType(); if (elementType == null) return; var instance = Activator.CreateInstance(elementType); if (fieldInfo.FieldType.IsArray) { var array = fieldInfo.GetValue(obj) as Array; var newArray = Array.CreateInstance(elementType, array.Length + 1); for (var i = 0; i < array.Length; i++) { newArray.SetValue(array.GetValue(i), i); } newArray.SetValue(instance, array.Length); fieldInfo.SetValue(obj, newArray); } else if (fieldInfo.FieldType.IsGenericType && fieldInfo.FieldType.GetGenericTypeDefinition() == typeof(List<>)) { var list = fieldInfo.GetValue(obj) as IList; list.Add(instance); } } private static Type GetArrayType(this Type type) { if (type.IsArray) return type.GetElementType(); if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) return type.GetGenericArguments()[0]; return null; }