private object InvokeMethod(IntPtr method, ParameterInfo[] parameterInfo, bool[] needBoxing) { object result; IntPtr methodReturn = _methodClass.GetReturnType(method); IntPtr jniMethodPtr = _vm.FromReflectedMethod(method); string returnTypeName = _classClass.GetName(methodReturn); JValue[] parameters = parameterInfo.Select((p, i) => p.Value(_vm, needBoxing[i])).ToArray(); PrimitiveType returnTypeAsPrimitive = PrimitiveType.FromString(_vm, returnTypeName); if (methodReturn == IntPtr.Zero || _classClass.GetName(methodReturn) == "void") { result = null; _vm.CallStaticVoidMethod(_jniClass, jniMethodPtr, parameters); } else if (returnTypeAsPrimitive != null) { switch (returnTypeAsPrimitive.Kind) { case PrimitiveTypeKind.Boolean: result = _vm.CallStaticBooleanMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Byte: result = _vm.CallStaticByteMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Char: result = _vm.CallStaticCharMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Double: result = _vm.CallStaticDoubleMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Float: result = _vm.CallStaticFloatMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Int: result = _vm.CallStaticIntMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Long: result = _vm.CallStaticLongMethod(_jniClass, jniMethodPtr, parameters); break; case PrimitiveTypeKind.Short: result = _vm.CallStaticShortMethod(_jniClass, jniMethodPtr, parameters); break; default: throw new InvalidOperationException("Unknown primitive type: " + returnTypeAsPrimitive.Kind); } } else { IntPtr methodResult = _vm.CallStaticObjectMethod(_jniClass, jniMethodPtr, parameters); if (methodResult != IntPtr.Zero) { if (returnTypeName.StartsWith("[")) { result = new JavaArray(_vm, methodResult, (ArrayType)JavaType.FromReflectedType(_vm, methodReturn)); } else { result = new JavaObject(_vm, methodResult, null); } } else { result = null; } } return(result); }