internal T InvokeMethod <T>(IntPtr id, IntPtr methodId, NativeValue[] parameters, bool isStatic) { Type type = typeof(T); if (type == typeof(object) || type == typeof(JObject) || type == typeof(string)) // We need to read string as it is the object. { var objectCaller = this.MethodCallers.Where(call => call is MethodCaller <IntPtr>).FirstOrDefault(); if (objectCaller != null) { var methodCaller = objectCaller as MethodCaller <IntPtr>; IntPtr pointer = methodCaller.Invoke(id, methodId, parameters, isStatic); // For string we need to read it. if (type == typeof(string)) { string str = this.Gateway.Runtime.JavaEnvironment.ReadJavaString(pointer); return((T)(object)str); } JavaType javaType = JavaMapper.GetRegisteredJavaTypes().Where(jt => jt.CSharpType == type).FirstOrDefault(); if (javaType != null) { IntPtr javaClass = this.Gateway.Runtime.JavaEnvironment.JNIEnv.GetObjectClass(pointer); return((T)(object)new JObject(this.Gateway, javaType.JavaTypeName, javaClass, pointer)); } } } else { var callers = this.MethodCallers.Where(call => call is MethodCaller <T>); var caller = callers.FirstOrDefault(); if (caller != null) { return((caller as MethodCaller <T>).Invoke(id, methodId, parameters, isStatic)); } } return(default(T)); }
internal static JavaType ToJniSignature(this Type type) { if (type.IsArray) { return(null); } // Try to get primitive type JavaType jt = JavaMapper.GetRegisteredJavaTypes().Where(javaType => javaType.CSharpType == type).FirstOrDefault(); if (jt != null) { return(jt); } string typeName = type.FullName; string jniTypeName = typeName.Replace(".", "/"); jt = new JavaType(typeName, typeName.ToJniSignatureString(), type); return(jt); }