Пример #1
0
			public static JavaObjectFactory Array(JniWrapper vm, Type dotNetType, Array prototype)
			{
				object innerPrototype = null;
				if (prototype != null && prototype.Length > 0)
				{
					innerPrototype = prototype.GetValue(0);
				}
				JavaObjectFactory innerFactory = GetJavaType(vm, dotNetType.GetElementType(), innerPrototype);
				ArrayType javaArrayType = new ArrayType(innerFactory.JavaType);
				return new JavaObjectFactory(o =>
					{
						Array asArray = (Array)o;
						PrimitiveType asPrimitive = javaArrayType.MemberType as PrimitiveType;
						if (asPrimitive != null)
						{
							switch (asPrimitive.Kind)
							{
								case PrimitiveTypeKind.Boolean: return vm.NewBooleanArray((bool[])o);
								case PrimitiveTypeKind.Byte: return vm.NewByteArray((byte[])o);
								case PrimitiveTypeKind.Char: return vm.NewCharArray((char[])o);
								case PrimitiveTypeKind.Double: return vm.NewDoubleArray((double[])o);
								case PrimitiveTypeKind.Float: return vm.NewFloatArray((float[])o);
								case PrimitiveTypeKind.Int: return vm.NewIntArray((int[])o);
								case PrimitiveTypeKind.Long: return vm.NewLongArray((long[])o);
								case PrimitiveTypeKind.Short: return vm.NewShortArray((short[])o);
								default: throw new InvalidOperationException("Unknown primitive kind: " + asPrimitive.Kind);
							}
						}
						else
						{
							IntPtr[] elements = asArray.Cast<object>().Select(innerFactory._factory).Select(v => v.ToIntPtr()).ToArray();
							return vm.NewArray(vm.FindClass(innerFactory.JavaType.JniClassName), elements);
						}
					}, javaArrayType);
			}
Пример #2
0
		public JavaArray(JniWrapper vm, IntPtr arrayPtr, ArrayType arrayType)
		{
			_vm = vm;
			_arrayPtr = arrayPtr;
			_arrayType = arrayType;
		}
Пример #3
0
			public static JavaObjectFactory Array(JniWrapper vm, ArrayType arrayType)
			{
				return new JavaObjectFactory(o => new JValue(((JavaArray)o).ArrayPointer), arrayType);
			}