|
1 | | -#nullable enable |
| 1 | +#nullable enable |
2 | 2 |
|
3 | 3 | using System; |
4 | 4 | using System.Collections.Generic; |
|
12 | 12 | namespace Java.Interop { |
13 | 13 |
|
14 | 14 | partial class JniRuntime { |
15 | | - static JniTypeSignature __BooleanTypeArraySignature; |
16 | | - static JniTypeSignature __SByteTypeArraySignature; |
17 | | - static JniTypeSignature __CharTypeArraySignature; |
18 | | - static JniTypeSignature __Int16TypeArraySignature; |
19 | | - static JniTypeSignature __Int32TypeArraySignature; |
20 | | - static JniTypeSignature __Int64TypeArraySignature; |
21 | | - static JniTypeSignature __SingleTypeArraySignature; |
22 | | - static JniTypeSignature __DoubleTypeArraySignature; |
23 | | - |
24 | | - static bool GetBuiltInTypeArraySignature (Type type, ref JniTypeSignature signature) |
25 | | - { |
26 | | - if (type == typeof (JavaArray<Boolean>) || type == typeof (JavaPrimitiveArray<Boolean>)) { |
27 | | - signature = GetCachedTypeSignature (ref __BooleanTypeArraySignature, "Z", arrayRank: 1, keyword: true); |
28 | | - return true; |
29 | | - } |
30 | | - if (type == typeof (JavaArray<SByte>) || type == typeof (JavaPrimitiveArray<SByte>)) { |
31 | | - signature = GetCachedTypeSignature (ref __SByteTypeArraySignature, "B", arrayRank: 1, keyword: true); |
32 | | - return true; |
33 | | - } |
34 | | - if (type == typeof (JavaArray<Char>) || type == typeof (JavaPrimitiveArray<Char>)) { |
35 | | - signature = GetCachedTypeSignature (ref __CharTypeArraySignature, "C", arrayRank: 1, keyword: true); |
36 | | - return true; |
37 | | - } |
38 | | - if (type == typeof (JavaArray<Int16>) || type == typeof (JavaPrimitiveArray<Int16>)) { |
39 | | - signature = GetCachedTypeSignature (ref __Int16TypeArraySignature, "S", arrayRank: 1, keyword: true); |
40 | | - return true; |
41 | | - } |
42 | | - if (type == typeof (JavaArray<Int32>) || type == typeof (JavaPrimitiveArray<Int32>)) { |
43 | | - signature = GetCachedTypeSignature (ref __Int32TypeArraySignature, "I", arrayRank: 1, keyword: true); |
44 | | - return true; |
45 | | - } |
46 | | - if (type == typeof (JavaArray<Int64>) || type == typeof (JavaPrimitiveArray<Int64>)) { |
47 | | - signature = GetCachedTypeSignature (ref __Int64TypeArraySignature, "J", arrayRank: 1, keyword: true); |
48 | | - return true; |
49 | | - } |
50 | | - if (type == typeof (JavaArray<Single>) || type == typeof (JavaPrimitiveArray<Single>)) { |
51 | | - signature = GetCachedTypeSignature (ref __SingleTypeArraySignature, "F", arrayRank: 1, keyword: true); |
52 | | - return true; |
53 | | - } |
54 | | - if (type == typeof (JavaArray<Double>) || type == typeof (JavaPrimitiveArray<Double>)) { |
55 | | - signature = GetCachedTypeSignature (ref __DoubleTypeArraySignature, "D", arrayRank: 1, keyword: true); |
56 | | - return true; |
57 | | - } |
58 | | - return false; |
| 15 | + |
| 16 | + partial class JniTypeManager { |
| 17 | + |
| 18 | + readonly struct JniPrimitiveArrayInfo { |
| 19 | + public readonly JniTypeSignature JniTypeSignature; |
| 20 | + public readonly Type PrimitiveType; |
| 21 | + public readonly Type[] ArrayTypes; |
| 22 | + |
| 23 | + public JniPrimitiveArrayInfo (string jniSimpleReference, Type primitiveType, params Type[] arrayTypes) |
| 24 | + { |
| 25 | + JniTypeSignature = new JniTypeSignature (jniSimpleReference, arrayRank: 1, keyword: true); |
| 26 | + PrimitiveType = primitiveType; |
| 27 | + ArrayTypes = arrayTypes; |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + static readonly JniPrimitiveArrayInfo[] JniPrimitiveArrayTypes = new JniPrimitiveArrayInfo[]{ |
| 32 | + new ("Z", typeof (Boolean), typeof (Boolean[]), typeof (JavaArray<Boolean>), typeof (JavaPrimitiveArray<Boolean>), typeof (JavaBooleanArray)), |
| 33 | + new ("B", typeof (SByte), typeof (SByte[]), typeof (JavaArray<SByte>), typeof (JavaPrimitiveArray<SByte>), typeof (JavaSByteArray)), |
| 34 | + new ("C", typeof (Char), typeof (Char[]), typeof (JavaArray<Char>), typeof (JavaPrimitiveArray<Char>), typeof (JavaCharArray)), |
| 35 | + new ("S", typeof (Int16), typeof (Int16[]), typeof (JavaArray<Int16>), typeof (JavaPrimitiveArray<Int16>), typeof (JavaInt16Array)), |
| 36 | + new ("I", typeof (Int32), typeof (Int32[]), typeof (JavaArray<Int32>), typeof (JavaPrimitiveArray<Int32>), typeof (JavaInt32Array)), |
| 37 | + new ("J", typeof (Int64), typeof (Int64[]), typeof (JavaArray<Int64>), typeof (JavaPrimitiveArray<Int64>), typeof (JavaInt64Array)), |
| 38 | + new ("F", typeof (Single), typeof (Single[]), typeof (JavaArray<Single>), typeof (JavaPrimitiveArray<Single>), typeof (JavaSingleArray)), |
| 39 | + new ("D", typeof (Double), typeof (Double[]), typeof (JavaArray<Double>), typeof (JavaPrimitiveArray<Double>), typeof (JavaDoubleArray)), |
| 40 | + }; |
| 41 | + |
| 42 | + static bool GetBuiltInTypeArraySignature (Type type, ref JniTypeSignature signature) |
| 43 | + { |
| 44 | + foreach (var e in JniPrimitiveArrayTypes) { |
| 45 | + if (Array.IndexOf (e.ArrayTypes, type) < 0) |
| 46 | + continue; |
| 47 | + signature = e.JniTypeSignature; |
| 48 | + return true; |
| 49 | + } |
| 50 | + signature = default; |
| 51 | + return false; |
| 52 | + } |
59 | 53 | } |
60 | 54 |
|
61 | 55 | static readonly Lazy<KeyValuePair<Type, JniValueMarshaler>[]> JniPrimitiveArrayMarshalers = new Lazy<KeyValuePair<Type, JniValueMarshaler>[]> (InitJniPrimitiveArrayMarshalers); |
|
0 commit comments