public static Class getPrimitiveClass(string name) { JNIEnv env = JNIEnv.ThreadEnv; MethodId id = env.GetStaticMethodID(staticClass, "getPrimitiveClass", "(Ljava/lang/String;)Ljava/lang/Class;"); return(Convertor.StrongJ2CpClass(env, env.CallStaticObjectMethodPtr(staticClass, id, Convertor.ParStrongC2JString(env, name)))); }
public static Class getPrimitiveClass(string name) { JNIEnv env = JNIEnv.ThreadEnv; try { Class shim = env.FindClass("com/koushikdutta/monojavabridge/MonoBridge"); MethodId shimMethodId = env.GetStaticMethodID(shim, "getPrimitiveClass", "(Ljava/lang/String;)Ljava/lang/Class;"); return(Convertor.StrongJ2CpClass(env, env.CallStaticObjectMethodPtr(shim, shimMethodId, Convertor.ParStrongC2JString(env, name)))); } catch (Exception) { } MethodId id = env.GetStaticMethodID(staticClass, "getPrimitiveClass", "(Ljava/lang/String;)Ljava/lang/Class;"); return(Convertor.StrongJ2CpClass(env, env.CallStaticObjectMethodPtr(staticClass, id, Convertor.ParStrongC2JString(env, name)))); }
private static JniLocalHandle PrimC2J(JNIEnv env, object obj, Type type) { if (type == typeof(int) || type == typeof(uint)) { Value value = ParPrimC2J((int)obj); return(env.CallStaticObjectMethodPtr(Integer.staticClass, intObject, value)); } if (type == typeof(long) || type == typeof(ulong)) { Value value = ParPrimC2J((long)obj); return(env.CallStaticObjectMethodPtr(Long.staticClass, longObject, value)); } if (type == typeof(bool)) { Value value = ParPrimC2J((bool)obj); return(env.CallStaticObjectMethodPtr(Boolean.staticClass, boolObject, value)); } if (type == typeof(double)) { Value value = ParPrimC2J((double)obj); return(env.CallStaticObjectMethodPtr(Double.staticClass, doubleObject, value)); } if (type == typeof(byte) || type == typeof(sbyte)) { Value value = ParPrimC2J((byte)obj); return(env.CallStaticObjectMethodPtr(Byte.staticClass, byteObject, value)); } if (type == typeof(char)) { Value value = ParPrimC2J((char)obj); return(env.CallStaticObjectMethodPtr(Character.staticClass, charObject, value)); } if (type == typeof(short) || type == typeof(ushort)) { Value value = ParPrimC2J((short)obj); return(env.CallStaticObjectMethodPtr(Short.staticClass, shortObject, value)); } if (type == typeof(float)) { Value value = ParPrimC2J((float)obj); return(env.CallStaticObjectMethodPtr(Float.staticClass, floatObject, value)); } throw new InvalidOperationException("Unknown simple type" + type); }