private static JavaType TypeByJniName(JniWrapper vm, string name) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } switch (name[0]) { case 'Z': return(PrimitiveType.Boolean(vm)); case 'B': return(PrimitiveType.Byte(vm)); case 'C': return(PrimitiveType.Char(vm)); case 'S': return(PrimitiveType.Short(vm)); case 'I': return(PrimitiveType.Int(vm)); case 'J': return(PrimitiveType.Long(vm)); case 'F': return(PrimitiveType.Float(vm)); case 'D': return(PrimitiveType.Double(vm)); case 'L': return(new JavaClass(vm, name.TrimStart('L').TrimEnd(';').Replace('/', '.'))); case '[': return(new ArrayType(TypeByJniName(vm, name.Substring(1)))); default: throw new InvalidOperationException("Can't decipher this JNI type name: " + name); } }
public static JavaObjectFactory Byte(JniWrapper vm) { return(new JavaObjectFactory(o => new JValue((byte)o), PrimitiveType.Byte(vm))); }
private JavaArray CreateArray(Array dotNetArray) { bool[] asBool; byte[] asByte; char[] asChar; double[] asDouble; float[] asFloat; int[] asInt; long[] asLong; short[] asShort; JavaObject[] asObject; if ((asBool = dotNetArray as bool[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewBooleanArray(asBool), new ArrayType(PrimitiveType.Boolean(_jniWrapper)))); } else if ((asByte = dotNetArray as byte[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewByteArray(asByte), new ArrayType(PrimitiveType.Byte(_jniWrapper)))); } else if ((asChar = dotNetArray as char[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewCharArray(asChar), new ArrayType(PrimitiveType.Char(_jniWrapper)))); } else if ((asDouble = dotNetArray as double[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewDoubleArray(asDouble), new ArrayType(PrimitiveType.Double(_jniWrapper)))); } else if ((asFloat = dotNetArray as float[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewFloatArray(asFloat), new ArrayType(PrimitiveType.Float(_jniWrapper)))); } else if ((asInt = dotNetArray as int[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewIntArray(asInt), new ArrayType(PrimitiveType.Int(_jniWrapper)))); } else if ((asLong = dotNetArray as long[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewLongArray(asLong), new ArrayType(PrimitiveType.Long(_jniWrapper)))); } else if ((asShort = dotNetArray as short[]) != null) { return(new JavaArray(_jniWrapper, _jniWrapper.NewShortArray(asShort), new ArrayType(PrimitiveType.Short(_jniWrapper)))); } else if ((asObject = dotNetArray as JavaObject[]) != null) { JavaObject prototype = asObject.FirstOrDefault(o => o != null); if (prototype == null) { throw new InvalidOperationException("Can't construct a Java array without at least one non-null object in there."); } return(new JavaArray(_jniWrapper, prototype.Class.NewArray(asObject.Select(o => o.Pointer).ToArray()), new ArrayType(prototype.Class))); } else { throw new InvalidOperationException("Can't construct a Java array from the given array of the given type: " + dotNetArray.GetType()); } }