Skip to content

[Java.Interop] ignore remaining trimming warnings #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 14, 2024
Prev Previous commit
Next Next commit
Cleaner suppressions for GetParameterMarshaler
  • Loading branch information
jonathanpeppers committed Feb 13, 2024
commit 9c7a05af6349f195b6c60a1150a156d53f8887e2
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,14 @@ string GetTypeSignature (ParameterInfo p)
throw new NotSupportedException ("Don't know how to determine JNI signature for parameter type: " + p.ParameterType.FullName + ".");
}

[UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = "Method parameter types should be preserved via other means.")]
public JniValueMarshaler GetParameterMarshaler (ParameterInfo parameter)
{
// Activator.CreateInstance requires DynamicallyAccessedMemberTypes.PublicParameterlessConstructor
// GetValueMarshaler requires DynamicallyAccessedMemberTypes.Interfaces
[UnconditionalSuppressMessage ("Trimming", "IL2072", Justification = "JniValueMarshalerAttribute is decorated with [DynamicallyAccessedMembers]")]
static JniValueMarshaler GetValueMarshaler (JniValueManager manager, ParameterInfo parameter) =>
manager.GetValueMarshaler (parameter.ParameterType);

if (parameter.ParameterType == typeof (IntPtr))
return IntPtrValueMarshaler.Instance;

Expand All @@ -165,7 +170,7 @@ public JniValueMarshaler GetParameterMarshaler (ParameterInfo parameter)
if (attr != null) {
return (JniValueMarshaler) Activator.CreateInstance (attr.MarshalerType)!;
}
return Runtime.ValueManager.GetValueMarshaler (parameter.ParameterType);
return GetValueMarshaler (Runtime.ValueManager, parameter);
}

// Heuristic: if first two parameters are IntPtr, this is a "direct" wrapper.
Expand Down
9 changes: 6 additions & 3 deletions src/Java.Interop/Java.Interop/JniValueMarshalerAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable
#nullable enable

using System;
using System.Diagnostics.CodeAnalysis;
Expand All @@ -8,13 +8,16 @@ namespace Java.Interop {

[AttributeUsage (Targets, AllowMultiple=false)]
public class JniValueMarshalerAttribute : Attribute {
const DynamicallyAccessedMemberTypes ParameterlessConstructorsInterfaces = DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.Interfaces;

const AttributeTargets Targets =
AttributeTargets.Class | AttributeTargets.Enum |
AttributeTargets.Interface | AttributeTargets.Struct |
AttributeTargets.Parameter | AttributeTargets.ReturnValue;

public JniValueMarshalerAttribute (Type marshalerType)
public JniValueMarshalerAttribute (
[DynamicallyAccessedMembers (ParameterlessConstructorsInterfaces)]
Type marshalerType)
{
if (marshalerType == null)
throw new ArgumentNullException (nameof (marshalerType));
Expand All @@ -27,7 +30,7 @@ public JniValueMarshalerAttribute (Type marshalerType)
}

public Type MarshalerType {
[return: DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[return: DynamicallyAccessedMembers (ParameterlessConstructorsInterfaces)]
get;
}
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy