private object ReadCollectionProperty_InitializeCollection(PropertyInfo property, Type targetType, IReader reader) { object collection = null; if (reader.CanSet(property)) { if (property.PropertyType.IsArray) { collection = Activator.CreateInstance(typeof(List <>).MakeGenericType(targetType)); } else { collection = Activator.CreateInstance(property.PropertyType); } } else { if (reader.CanGet(property)) { collection = reader.Get(property); } if (collection == null) { throw new InvalidOperationException($"The value of the property {property.DeclaringType.FullName}.{property.Name} has no set accessor and is not initialized by default"); } } return(collection); }