ironpython2 icon indicating copy to clipboard operation
ironpython2 copied to clipboard

It seems that new features in C# cause the Genetic index can't be used

Open bnuzhouwei opened this issue 3 years ago • 1 comments

In opencvsharp:

public ref T At<T>(params int[] idx) where T : unmanaged;

In my program:

confidence = detectionMat.At[float]((i, 2))

Got an error:

System.ArgumentException: The type 'System.Double&' may not be used as a type argument.

It seems that new features in C#: A reference return value is defined by using the ref keyword cause the Genetic index can't be used.

bnuzhouwei avatar Jan 08 '21 01:01 bnuzhouwei

There are likely a number of changes that would need to be made to the DLR (and IronPython) to support this. I tried the following change to CallInstruction.Create

if (info.ReturnType.IsByRef) {
    return new MethodInfoCallInstruction(info, argumentCount);
}

but it then fails with:

ByRef return value not supported in reflection invocation


Maybe you could try to define a C# extension method which avoids the ref return? I'm not sure...

public void GetAt<T>(int[] idx, ref T value) => value = At(idx);

slozier avatar Jan 18 '21 19:01 slozier