It'd be really good if I could get an object to array conversion working.
Steps:
- We get passed an array from an external source. The array is boxed in an object. Typically the object is an int[] or a double[], but we normally want double[].
- Convert it to an array of Type T.
- return the converted type.
For starters, this works fine
double[] r=Array.ConvertAll<int,double>((int[])o,Convert.ToDouble)
but this doesn't (assume that T is "double") e.g. double[] R=getValue(o);
public T[] getValue<T>(object o){
// ... some logic...
return (T[])Array.ConvertAll<int,double>((int[])o,Convert.ToDouble)
Is there a where constraint that can be used? Array is a "Special Object", so we can't use that as a constraint.
Is this possible in .net without resorting to IL? Is it possilbe if we do resort to IL?
thanks, -Steven