Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Java.Interop/Java.Interop/JniBuiltinMarshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static bool GetBuiltInTypeSignature (Type type, ref JniTypeSignature signature)
case TypeCode.Boolean:
signature = GetCachedTypeSignature (ref __BooleanTypeSignature, "Z", arrayRank: 0, keyword: true);
return true;
case TypeCode.Byte:
case TypeCode.SByte:
signature = GetCachedTypeSignature (ref __SByteTypeSignature, "B", arrayRank: 0, keyword: true);
return true;
Expand Down
13 changes: 10 additions & 3 deletions src/Java.Interop/Java.Interop/JniBuiltinMarshalers.tt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ namespace Java.Interop {
return true;
<#
foreach (var type in types) {
if (type.Name == "Byte") {
#>
case TypeCode.Byte:
<#
}
#>
case TypeCode.<#= type.Type #>:
signature = GetCachedTypeSignature (ref __<#= type.Type #>TypeSignature, "<#= type.JniType #>", arrayRank: 0, keyword: true);
Expand Down Expand Up @@ -185,7 +190,7 @@ namespace Java.Interop {
public override object? CreateValue (
ref JniObjectReference reference,
JniObjectReferenceOptions options,
[DynamicallyAccessedMembers (ConstructorsAndInterfaces)]
[DynamicallyAccessedMembers (Constructors)]
Type? targetType)
{
if (!reference.IsValid)
Expand All @@ -196,7 +201,7 @@ namespace Java.Interop {
public override <#= type.Type #> CreateGenericValue (
ref JniObjectReference reference,
JniObjectReferenceOptions options,
[DynamicallyAccessedMembers (ConstructorsAndInterfaces)]
[DynamicallyAccessedMembers (Constructors)]
Type? targetType)
{
if (!reference.IsValid)
Expand Down Expand Up @@ -230,6 +235,7 @@ namespace Java.Interop {
state = new JniValueMarshalerState ();
}

[RequiresDynamicCode (ExpressionRequiresUnreferencedCode)]
[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type? targetType)
{
Expand All @@ -242,6 +248,7 @@ namespace Java.Interop {
return sourceValue;
}

[RequiresDynamicCode (ExpressionRequiresUnreferencedCode)]
[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
{
Expand All @@ -256,7 +263,7 @@ namespace Java.Interop {
public override <#= type.Type #>? CreateGenericValue (
ref JniObjectReference reference,
JniObjectReferenceOptions options,
[DynamicallyAccessedMembers (ConstructorsAndInterfaces)]
[DynamicallyAccessedMembers (Constructors)]
Type? targetType)
{
if (!reference.IsValid)
Expand Down
4 changes: 2 additions & 2 deletions src/Java.Interop/Java.Interop/JniRuntime.JniTypeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public JniTypeSignature GetTypeSignature (Type type)
if (type == null)
throw new ArgumentNullException (nameof (type));
if (type.ContainsGenericParameters)
throw new ArgumentException ($"'{type}' contains a generic type definition. This is not supported.", nameof (type));
throw new NotSupportedException ($"'{type}' contains a generic type definition. This is not supported.");

type = GetUnderlyingType (type, out int rank);

Expand Down Expand Up @@ -184,7 +184,7 @@ public IEnumerable<JniTypeSignature> GetTypeSignatures (Type type)
if (type == null)
yield break;
if (type.ContainsGenericParameters)
throw new ArgumentException ($"'{type}' contains a generic type definition. This is not supported.", nameof (type));
throw new NotSupportedException ($"'{type}' contains a generic type definition. This is not supported.");

type = GetUnderlyingType (type, out int rank);

Expand Down
9 changes: 6 additions & 3 deletions tests/Java.Interop-Tests/Java.Interop/JniTypeManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void GetTypeSignature_Type ()
Assert.Throws<ArgumentException>(() => JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (typeof (int[,])));
Assert.Throws<ArgumentException>(() => JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (typeof (int[,][])));
Assert.Throws<ArgumentException>(() => JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (typeof (int[][,])));
Assert.Throws<ArgumentException>(() => JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (typeof (Action<>)));
Assert.Throws<NotSupportedException>(() => JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (typeof (Action<>)));
Assert.AreEqual (null, JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (typeof (JniRuntimeTest)).SimpleReference);

AssertGetJniTypeInfoForType (typeof (string), "java/lang/String", false, 0);
Expand All @@ -40,6 +40,7 @@ public void GetTypeSignature_Type ()
AssertGetJniTypeInfoForType (typeof (StringComparison[]), "[I", true, 1);
AssertGetJniTypeInfoForType (typeof (StringComparison[][]), "[[I", true, 2);

AssertGetJniTypeInfoForType (typeof (byte[]), "[B", true, 1);
AssertGetJniTypeInfoForType (typeof (int[]), "[I", true, 1);
AssertGetJniTypeInfoForType (typeof (int[][]), "[[I", true, 2);
AssertGetJniTypeInfoForType (typeof (int[][][]), "[[[I", true, 3);
Expand Down Expand Up @@ -89,14 +90,16 @@ public void GetTypeSignature_Type ()
static void AssertGetJniTypeInfoForType (Type type, string jniType, bool isKeyword, int arrayRank)
{
var info = JniRuntime.CurrentRuntime.TypeManager.GetTypeSignature (type);
Assert.IsTrue (info.IsValid, $"info.IsValid for `{type}`");

// `GetTypeSignature() and `GetTypeSignatures()` should be "in sync"; verify that!
var info2 = JniRuntime.CurrentRuntime.TypeManager.GetTypeSignatures (type).FirstOrDefault ();
Assert.IsTrue (info2.IsValid, $"info2.IsValid for `{type}`");

Assert.AreEqual (jniType, info.Name, $"info.Name for `{type}`");
Assert.AreEqual (jniType, info2.Name, $"info.Name for `{type}`");
Assert.AreEqual (jniType, info2.Name, $"info2.Name for `{type}`");
Assert.AreEqual (arrayRank, info.ArrayRank, $"info.ArrayRank for `{type}`");
Assert.AreEqual (arrayRank, info2.ArrayRank, $"info.ArrayRank for `{type}`");
Assert.AreEqual (arrayRank, info2.ArrayRank, $"info2.ArrayRank for `{type}`");
}

[Test]
Expand Down