문제

I Wanted to convert a c# code to j# and somehow managed to get over dllimport and marshalas.

Problem is, when a function has a reference to an object - ref isn't recognized

public static native int Mathod(ref Type type, int flags);

Anyone has any experience with j# and know how to send references to a method (or define a type in a method as a reference)

도움이 되었습니까?

해결책

I'm pretty sure that you can't do this directly.

Everything is passed by value in real Java, and presumably in J# too.

In recent versions of Java you can workaround the restriction by using AtomicReference, but I very much doubt that J# is up-to-date enough to support this.

You could try changing the method signature to accept a single-element Type[] array, and then mutate that array element. This would allow you to achieve a similar outcome to ref. The downside is that you'd need to change the call-site and the method itself to wrap and unwrap the variable in the array. (Although you could create your own custom type to encapsulate the wrapping and unwrapping if it simplifies things.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top