dotnet / java-interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Other
189 stars 48 forks source link

Add support for `long` enumification #1187

Open jpobst opened 5 months ago

jpobst commented 5 months ago

Context: https://github.com/xamarin/xamarin-android/pull/8182 Context: https://github.com/xamarin/xamarin-android/pull/8707

We have now had 2 instances of enumification values in android.jar requiring long enums instead of int enums. As generator doesn't have any support for long enums, these had to be handled manually. Additionally, if the long enum is manually created and added to the api with:

  <add-node api-since="34" path="/api">
    <enum name="Android.Hardware.HardwareBufferUsage" />
  </add-node>

it will create the correct API, but the binding code will be created as int rather than long:

[Register ("create", "(IIIII)Landroid/hardware/HardwareBuffer;", "", ApiSince = 26)]
public static unsafe Android.Hardware.HardwareBuffer Create (int width, int height, [global::Android.Runtime.GeneratedEnum] Android.Hardware.HardwareBufferFormat format, int layers, Android.Hardware.HardwareBufferUsage usage)
{
    const string __id = "create.(IIIII)Landroid/hardware/HardwareBuffer;";
    try {
        JniArgumentValue* __args = stackalloc JniArgumentValue [5];
        __args [0] = new JniArgumentValue (width);
        __args [1] = new JniArgumentValue (height);
        __args [2] = new JniArgumentValue ((int) format);
        __args [3] = new JniArgumentValue (layers);
        __args [4] = new JniArgumentValue ((int) usage);
        var __rm = _members.StaticMethods.InvokeObjectMethod (__id, __args);
        return global::Java.Lang.Object.GetObject<Android.Hardware.HardwareBuffer> (__rm.Handle, JniHandleOwnership.TransferLocalRef)!;
    } finally {
    }
}

This requires the method to be hand-bound to fix the binding.