Question

I'm attempting to create a method which will allow me to copy observable collection to another using reflection. The observable collection would be part of the DTO which i am copying, and hence i need to uniquely identify whether its an Observable Collection /List.

Thank you.. Rithesh

Was it helpful?

Solution

Copying collection to list can be done with Enumerable.ToList extension method.

If you want to detect type via reflection - Type.IsGenericType and Type.GetGenericTypeDefinition will let you detect if type of given object is ObservableCollection<T>. Than Type.GetGenericArguments will give the exact type. At that point you should be able to create your own collection of element of that type and copy elements from original collection into new one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top