internal static object GetObject(JNIEnv env, JniHandle obj) { long handle = getClrHandle(env, obj); if (handle == 0) { return(null); } object real = IntHandle.ToObject(handle); return(real); }
private static JniHandle UnwrapJVM(IntPtr __envp, IntPtr __class, long clrHandle) { JNIEnv env = JNIEnv.Wrap(__envp); try { IJvmProxy jvmProxy = (IJvmProxy)IntHandle.ToObject(clrHandle); return(jvmProxy.JvmHandle); } catch (Exception ex) { env.ThrowExisting(ex); } return(JniGlobalHandle.Zero); }
public static TRes UnwrapCLR <TRes>(Object obj) { var clrProxy = obj as IClrProxy; if (clrProxy == null) { throw new JNIException("Can't unwrap JVM instance"); } long handle = clrProxy.getClrHandle(); object res = IntHandle.ToObject(handle); Type type = res.GetType(); Type reqType = typeof(TRes); if (!reqType.IsAssignableFrom(type)) { throw new InvalidCastException("Can't cast CLR instance of " + type + " to " + reqType); } return((TRes)res); }