private static long Convert(IntPtr __envp, JniLocalHandle __class, JniLocalHandle str)
 {
     JNIEnv env = JNIEnv.Wrap(__envp);
     try
     {
         string value = env.ConvertToString(str);
         return IntHandle.Alloc(value);
     }
     catch (Exception ex)
     {
         env.ThrowExisting(ex);
     }
     return default(long);
 }
        private static JniLocalHandle Cast(IntPtr @__envp, JniLocalHandle @__class, JniLocalHandle obj, JniLocalHandle expectedInterface)
        {
            JNIEnv env = JNIEnv.Wrap(@__envp);
            try
            {
                Class expectedInterfaceClass = Convertor.StrongJ2CpClass(env, expectedInterface);
                object real = __IClrProxy.GetObject(env, obj);
                Type type = real.GetType();
                RegistryRecord record = Registry.GetJVMRecord(expectedInterfaceClass);
                Type reqType = record.CLRInterface;
                if (!reqType.IsAssignableFrom(type))
                {
                    throw new InvalidCastException("Can't convert instance of CLR type " + type + " to " + reqType);
                }

                return record.CreateJVMProxy(env, real);
            }
            catch (Exception ex)
            {
                env.ThrowExisting(ex);
            }
            return JniLocalHandle.Zero;
        }
예제 #3
0
파일: String.cs 프로젝트: Mazrick/jni4net
 internal static String CreateProxy(JNIEnv env, JniLocalHandle obj)
 {
     var proxy = new String(env);
     ((IJvmProxy) proxy).Init(env, obj);
     return proxy;
 }
예제 #4
0
 internal static IClrProxy CreateProxy(JNIEnv env, JniLocalHandle obj)
 {
     IClrProxy proxy = new __IClrProxy(env);
     proxy.Init(env, obj);
     return proxy;
 }
 private static long WrapJVM(IntPtr __envp, JniLocalHandle __class, JniLocalHandle obj)
 {
     JNIEnv env = JNIEnv.Wrap(__envp);
     try
     {
         Class clazz = env.GetObjectClass(obj);
         RegistryRecord record = Registry.GetJVMRecord(clazz);
         IJvmProxy clrProxy = record.CreateCLRProxy(env, obj);
         return IntHandle.Alloc(clrProxy);
     }
     catch (Exception ex)
     {
         env.ThrowExisting(ex);
     }
     return 0;
 }
예제 #6
0
 public static void InitProxy(JNIEnv env, JniLocalHandle obj, object real)
 {
     long handle = IntHandle.Alloc(real);
     env.CallVoidMethod(obj, __IClrProxy._initProxy1, new Value {_long = handle});
 }
예제 #7
0
 internal IJvmProxy CreateCLRProxy(JNIEnv env, JniLocalHandle obj)
 {
     IJvmProxy proxy = CLRConstructor.CreateProxy(env);
     proxy.Init(env, obj);
     return proxy;
 }