/// <summary> /// Hack using reflection to get a pointer to java jni SetByteArrayRegion function pointer /// </summary> private static void GetSetArrayRegionFunctionPointer() { // ReSharper disable PossibleNullReferenceException try { var jniEnvGetter = typeof(JNIEnv).GetMethod("get_Env", BindingFlags.Static | BindingFlags.NonPublic); var jniEnvInstanceField = jniEnvGetter.ReturnType.GetField("JniEnv", BindingFlags.NonPublic | BindingFlags.Instance); var setByteArrayFunctionField = jniEnvInstanceField.FieldType.GetField("SetByteArrayRegion", BindingFlags.Public | BindingFlags.Instance); var jniEnvInstance = jniEnvInstanceField.GetValue(jniEnvGetter.Invoke(null, null)); var pointerToSetByteArrayFunction = (IntPtr)setByteArrayFunctionField.GetValue(jniEnvInstance); setJavaByteArray = Marshal.GetDelegateForFunctionPointer <SetJavaByteArrayRegionDelegate>(pointerToSetByteArrayFunction); } catch (Exception) { setJavaByteArray = null; } // ReSharper restore PossibleNullReferenceException }
/// <summary> /// Hack using reflection to get a pointer to java jni SetByteArrayRegion function pointer /// </summary> private static void GetSetArrayRegionFunctionPointer() { // ReSharper disable PossibleNullReferenceException try { var jniEnvGetter = typeof(JNIEnv).GetMethod("get_Env", BindingFlags.Static | BindingFlags.NonPublic); var jniEnvInstanceField = jniEnvGetter.ReturnType.GetField("JniEnv", BindingFlags.NonPublic | BindingFlags.Instance); var setByteArrayFunctionField = jniEnvInstanceField.FieldType.GetField("SetByteArrayRegion", BindingFlags.Public | BindingFlags.Instance); var jniEnvInstance = jniEnvInstanceField.GetValue(jniEnvGetter.Invoke(null, null)); var pointerToSetByteArrayFunction = (IntPtr)setByteArrayFunctionField.GetValue(jniEnvInstance); setJavaByteArray = Marshal.GetDelegateForFunctionPointer<SetJavaByteArrayRegionDelegate>(pointerToSetByteArrayFunction); } catch (Exception) { setJavaByteArray = null; } // ReSharper restore PossibleNullReferenceException }