Passing dynamic Type at runtime in Array.ConvertAll

Viewed 34

Is it possible to pass Dynamic Type in Array.ConvertAll? in the below code instead of Int32.Parse I tried passing or is there any other way to convert my array of values to another data type

var criteria = Array.ConvertAll(filter.Value, Int32.Parse);

MemberExpression member = Expression.Property(param, filter.Name);
var propertyType = ((PropertyInfo)member.Member).PropertyType;

var criteria = Array.ConvertAll(filter.Value, propertyType); // Gives error
1 Answers

If you want to convert type from an array but we want to determine the type in runtime.

we can try to use Convert.ChangeType method in the second parameter from Array.ConvertAll

var criteria = Array.ConvertAll(arr, (o)=> Convert.ChangeType(o,propertyType)); 
Related