I'd like to create a generic method that uses a pointer to an array of T where T could be a C# primitive, or a C# class. I was going along fine until I attempted the "T" part.
Is there a way around the error "can not declare a pointer to a non unmanaged type TIn"
I tried to use pinning via the "fixed" keyword to make this possible.
public static object DoSomething<TIn, TOut>(object SObj, Action<TIn, TOut> takeAction)
{
double[]A = (double[]) SObj;
TIn[]B = new TIn[5];
unsafe
{
fixed (double* dbl = A) // <--- works okay
{
}
fixed (TIn* Sptr = B) // <--- fails
{
}
}
}
--
@dtb: just checked out blittable. "One-dimensional arrays of blittable types, such as an array of integers. However, a type that contains a variable array of blittable types is not itself blittable." Even if there was a biltable constraint, it seems like they've limited it to arrays of one dimension.