public unsafe void Dispose_Exceptions() { var t = new JniType("java/lang/Object"); t.Dispose(); Assert.Throws <ObjectDisposedException> (() => t.AllocObject()); Assert.Throws <ObjectDisposedException> (() => t.NewObject(null, null)); Assert.Throws <ObjectDisposedException> (() => t.GetConstructor(null)); Assert.Throws <ObjectDisposedException> (() => t.GetInstanceField(null, null)); Assert.Throws <ObjectDisposedException> (() => t.GetInstanceMethod(null, null)); Assert.Throws <ObjectDisposedException> (() => t.GetStaticField(null, null)); Assert.Throws <ObjectDisposedException> (() => t.GetStaticMethod(null, null)); Assert.Throws <ObjectDisposedException> (() => t.GetSuperclass()); Assert.Throws <ObjectDisposedException> (() => t.IsAssignableFrom(null)); Assert.Throws <ObjectDisposedException> (() => t.IsInstanceOfType(new JniObjectReference())); Assert.Throws <ObjectDisposedException> (() => t.RegisterWithRuntime()); Assert.Throws <ObjectDisposedException> (() => t.RegisterNativeMethods(null)); Assert.Throws <ObjectDisposedException> (() => t.UnregisterNativeMethods()); JniFieldInfo jif = null; Assert.Throws <ObjectDisposedException> (() => t.GetCachedInstanceField(ref jif, null, null)); JniMethodInfo jim = null; Assert.Throws <ObjectDisposedException> (() => t.GetCachedConstructor(ref jim, null)); Assert.Throws <ObjectDisposedException> (() => t.GetCachedInstanceMethod(ref jim, null, null)); JniFieldInfo jsf = null; Assert.Throws <ObjectDisposedException> (() => t.GetCachedStaticField(ref jsf, null, null)); JniMethodInfo jsm = null; Assert.Throws <ObjectDisposedException> (() => t.GetCachedStaticMethod(ref jsm, null, null)); }
static string _GetMessage(IntPtr handle) { if (handle == IntPtr.Zero) { return(null); } IntPtr value; #if JAVA_INTEROP const string __id = "getMessage.()Ljava/lang/String;"; if (Throwable_getMessage == null) { Throwable_getMessage = _members.InstanceMethods.GetMethodInfo(__id); } value = JniEnvironment.InstanceMethods.CallObjectMethod(new JniObjectReference(handle), Throwable_getMessage).Handle; #else // !JAVA_INTEROP if (id_getMessage == IntPtr.Zero) { id_getMessage = JNIEnv.GetMethodID(class_ref, "getMessage", "()Ljava/lang/String;"); } value = JNIEnv.CallObjectMethod(handle, id_getMessage); #endif // !JAVA_INTEROP return(JNIEnv.GetString(value, JniHandleOwnership.TransferLocalRef)); }
static JavaClassInfo() { CreatePeerMembers = (Func <string, Type, JniPeerMembers>) typeof(JniPeerMembers) .GetTypeInfo() .GetDeclaredMethod("CreatePeerMembers") .CreateDelegate(typeof(Func <string, Type, JniPeerMembers>)); if (CreatePeerMembers == null) { throw new NotSupportedException("Could not find JniPeerMembers.CreatePeerMembers!"); } using (var t = new JniType("java/lang/Class")) { Class_getConstructors = t.GetInstanceMethod("getConstructors", "()[Ljava/lang/reflect/Constructor;"); Class_getFields = t.GetInstanceMethod("getFields", "()[Ljava/lang/reflect/Field;"); Class_getMethods = t.GetInstanceMethod("getMethods", "()[Ljava/lang/reflect/Method;"); } using (var t = new JniType("java/lang/reflect/Constructor")) { Constructor_getParameterTypes = t.GetInstanceMethod("getParameterTypes", "()[Ljava/lang/Class;"); } using (var t = new JniType("java/lang/reflect/Field")) { Field_getName = t.GetInstanceMethod("getName", "()Ljava/lang/String;"); Field_getType = t.GetInstanceMethod("getType", "()Ljava/lang/Class;"); } using (var t = new JniType("java/lang/reflect/Method")) { Method_getName = t.GetInstanceMethod("getName", "()Ljava/lang/String;"); Method_getParameterTypes = t.GetInstanceMethod("getParameterTypes", "()[Ljava/lang/Class;"); Method_getReturnType = t.GetInstanceMethod("getReturnType", "()Ljava/lang/Class;"); } using (var t = new JniType("java/lang/reflect/Member")) { Member_getModifiers = t.GetInstanceMethod("getModifiers", "()I"); } }
static global::System.Exception _GetInnerException (IntPtr handle) { if (handle == IntPtr.Zero) return null; IntPtr value; #if JAVA_INTEROP const string __id = "getCause.()Ljava/lang/Throwable;"; if (Throwable_getCause == null) { Throwable_getCause = _members.InstanceMethods.GetMethodInfo (__id); } value = JniEnvironment.InstanceMethods.CallObjectMethod (new JniObjectReference (handle), Throwable_getCause).Handle; #else // !JAVA_INTEROP if (id_getCause == IntPtr.Zero) id_getCause = JNIEnv.GetMethodID (class_ref, "getCause", "()Ljava/lang/Throwable;"); value = JNIEnv.CallObjectMethod (handle, id_getCause); #endif // !JAVA_INTEROP var cause = global::Java.Lang.Object.GetObject<Java.Lang.Throwable> ( value, JniHandleOwnership.TransferLocalRef); var proxy = cause as JavaProxyThrowable; if (proxy != null) return proxy.InnerException; return cause; }
public unsafe int VirtualIntMethod1Args(int value) { TypeRef.GetCachedInstanceMethod(ref vim1, "VirtualIntMethod1Args", "(I)I"); var args = stackalloc JniArgumentValue [1]; args [0] = new JniArgumentValue(value); int r; if (GetType() == _members.ManagedPeerType) { r = JniEnvironment.InstanceMethods.CallIntMethod(PeerReference, vim1, args); } else { JniMethodInfo m = JniPeerMembers.InstanceMethods.GetMethodInfo("VirtualIntMethod1Args.(I)I"); r = JniEnvironment.InstanceMethods.CallNonvirtualIntMethod(PeerReference, JniPeerMembers.JniPeerType.PeerReference, m, args); } return(r); }
static string _GetMessage (IntPtr handle) { if (handle == IntPtr.Zero) return null; IntPtr value; #if JAVA_INTEROP const string __id = "getMessage.()Ljava/lang/String;"; if (Throwable_getMessage == null) { Throwable_getMessage = _members.InstanceMethods.GetMethodInfo (__id); } value = JniEnvironment.InstanceMethods.CallObjectMethod (new JniObjectReference (handle), Throwable_getMessage).Handle; #else // !JAVA_INTEROP if (id_getMessage == IntPtr.Zero) id_getMessage = JNIEnv.GetMethodID (class_ref, "getMessage", "()Ljava/lang/String;"); value = JNIEnv.CallObjectMethod (handle, id_getMessage); #endif // !JAVA_INTEROP return JNIEnv.GetString (value, JniHandleOwnership.TransferLocalRef); }
public unsafe int VirtualIntMethod1Args(int[][][] value) { TypeRef.GetCachedInstanceMethod(ref vim1_a, "VirtualIntMethod1Args", "([[[I)I"); int r; using (var native_array = new JavaObjectArray <int[][]> (value)) { var args = stackalloc JniArgumentValue [1]; args [0] = new JniArgumentValue(native_array); if (GetType() == _members.ManagedPeerType) { r = JniEnvironment.InstanceMethods.CallIntMethod(PeerReference, vim1_a, args); } else { JniMethodInfo m = JniPeerMembers.InstanceMethods.GetMethodInfo("VirtualIntMethod1Args.([[[I)I"); r = JniEnvironment.InstanceMethods.CallNonvirtualIntMethod(PeerReference, JniPeerMembers.JniPeerType.PeerReference, m, args); } native_array.CopyTo(value, 0); } return(r); }
static global::System.Exception _GetInnerException(IntPtr handle) { if (handle == IntPtr.Zero) { return(null); } IntPtr value; #if JAVA_INTEROP const string __id = "getCause.()Ljava/lang/Throwable;"; if (Throwable_getCause == null) { Throwable_getCause = _members.InstanceMethods.GetMethodInfo(__id); } value = JniEnvironment.InstanceMethods.CallObjectMethod(new JniObjectReference(handle), Throwable_getCause).Handle; #else // !JAVA_INTEROP if (id_getCause == IntPtr.Zero) { id_getCause = JNIEnv.GetMethodID(class_ref, "getCause", "()Ljava/lang/Throwable;"); } value = JNIEnv.CallObjectMethod(handle, id_getCause); #endif // !JAVA_INTEROP var cause = global::Java.Lang.Object.GetObject <Java.Lang.Throwable> ( value, JniHandleOwnership.TransferLocalRef); var proxy = cause as JavaProxyThrowable; if (proxy != null) { return(proxy.InnerException); } return(cause); }