I have a function that uses reflection to set properties of object A from object B. At one point, I need to instantiate a generic collection. However, I am unable to get it working. Here is what I have now:
IList list = destProperty.PropertyType.GetGenericTypeDefinition()
.MakeGenericType(destProperty.PropertyType.GetGenericArguments())
.GetConstructor(Type.EmptyTypes)
.Invoke(null) as IList;
I am trying to set the value of the destProperty. It has to be a List At runtime, the destProperty is of type ICollection<>. I think what's happening is that since ICollection is an interface, it has no constructor. What is the proper way to instantiate it then?
Thanks!