Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion src/Mono.Android/Android.Graphics/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,18 @@ public static void RGBToHSV (int red, int green, int blue, float[] hsv)

public class ColorValueMarshaler : JniValueMarshaler<Color>
{
const DynamicallyAccessedMemberTypes ConstructorsAndInterfaces = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces;
const string ExpressionRequiresUnreferencedCode = "System.Linq.Expression usage may trim away required code.";

public override Type MarshalType {
get { return typeof (int); }
}

public override Color CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type targetType)
public override Color CreateGenericValue (
ref JniObjectReference reference,
JniObjectReferenceOptions options,
[DynamicallyAccessedMembers (ConstructorsAndInterfaces)]
Type targetType)
{
throw new NotImplementedException ();
}
Expand All @@ -414,6 +421,7 @@ public override void DestroyGenericArgumentState (Color value, ref JniValueMarsh
throw new NotImplementedException ();
}

[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType)
{
var c = typeof (Color).GetConstructor (new[]{typeof (int)})!;
Expand All @@ -424,6 +432,7 @@ public override Expression CreateParameterToManagedExpression (JniValueMarshaler
return v;
}

[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateParameterFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize)
{
var r = Expression.Variable (MarshalType, sourceValue.Name + "_p");
Expand All @@ -433,6 +442,7 @@ public override Expression CreateParameterFromManagedExpression (JniValueMarshal
return r;
}

[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
{
return CreateParameterFromManagedExpression (context, sourceValue, 0);
Expand Down
11 changes: 10 additions & 1 deletion src/Mono.Android/Android.Runtime/IJavaObjectValueMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ namespace Android.Runtime
{
sealed class IJavaObjectValueMarshaler : JniValueMarshaler<IJavaObject> {

const DynamicallyAccessedMemberTypes ConstructorsAndInterfaces = DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors | DynamicallyAccessedMemberTypes.Interfaces;
const string ExpressionRequiresUnreferencedCode = "System.Linq.Expression usage may trim away required code.";

internal static IJavaObjectValueMarshaler Instance = new IJavaObjectValueMarshaler ();

public override IJavaObject CreateGenericValue (ref JniObjectReference reference, JniObjectReferenceOptions options, Type? targetType)
public override IJavaObject CreateGenericValue (
ref JniObjectReference reference,
JniObjectReferenceOptions options,
[DynamicallyAccessedMembers (ConstructorsAndInterfaces)]
Type? targetType)
{
throw new NotImplementedException ();
}
Expand All @@ -27,6 +34,7 @@ public override void DestroyGenericArgumentState ([AllowNull]IJavaObject value,
throw new NotImplementedException ();
}

[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
{
return Expression.Call (
Expand All @@ -36,6 +44,7 @@ public override Expression CreateReturnValueFromManagedExpression (JniValueMarsh
sourceValue);
}

[RequiresUnreferencedCode (ExpressionRequiresUnreferencedCode)]
public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type? targetType)
{
var r = Expression.Variable (targetType, sourceValue.Name + "_val");
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/System.Drawing/PointConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.ComponentModel.Design.Serialization;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -133,6 +134,7 @@ public override bool GetCreateInstanceSupported (ITypeDescriptorContext context)
return true;
}

[RequiresUnreferencedCode ("The Type of value cannot be statically discovered.")]
public override PropertyDescriptorCollection? GetProperties (
ITypeDescriptorContext context,
object value, Attribute[] attributes)
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/System.Drawing/RectangleConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

using System.ComponentModel;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Text;
using System.ComponentModel.Design.Serialization;
Expand Down Expand Up @@ -147,6 +148,7 @@ public override bool GetCreateInstanceSupported (ITypeDescriptorContext context)
return true;
}

[RequiresUnreferencedCode ("The Type of value cannot be statically discovered.")]
public override PropertyDescriptorCollection? GetProperties (
ITypeDescriptorContext context,
object value, Attribute[] attributes)
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/System.Drawing/SizeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
Expand Down Expand Up @@ -135,6 +136,7 @@ public override bool GetCreateInstanceSupported (ITypeDescriptorContext context)
return true;
}

[RequiresUnreferencedCode ("The Type of value cannot be statically discovered.")]
public override PropertyDescriptorCollection? GetProperties (
ITypeDescriptorContext context,
object value, Attribute[] attributes)
Expand Down
2 changes: 2 additions & 0 deletions src/Mono.Android/System.Drawing/SizeFConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
Expand Down Expand Up @@ -118,6 +119,7 @@ public override bool GetCreateInstanceSupported (ITypeDescriptorContext context)
return true;
}

[RequiresUnreferencedCode ("The Type of value cannot be statically discovered.")]
public override PropertyDescriptorCollection? GetProperties (ITypeDescriptorContext context, object value, Attribute[] attributes)
{
if (value is SizeF)
Expand Down
11 changes: 3 additions & 8 deletions src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,9 @@ protected virtual Task SetupRequest (HttpRequestMessage request, HttpURLConnecti
object? GetUnderlyingHandler ()
{
var fieldName = "_nativeHandler";
FieldInfo? field = null;

for (var type = GetType (); type != null; type = type.BaseType) {
field = type.GetField (fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
break;
}

const BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
FieldInfo? field = typeof (HttpClientHandler).GetField (fieldName, flags) ??
typeof (HttpMessageHandler).GetField (fieldName, flags);
if (field == null) {
throw new InvalidOperationException ($"Field '{fieldName}' is missing from type '{GetType ()}'.");
}
Expand Down