Skip to content

Commit 1e01dda

Browse files
committed
Make NativeTypeConversion be public to prevent MethodAccessException if trimming is ON.
1 parent 226c5c5 commit 1e01dda

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

MacOS/NativeTypeConversion.cs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
namespace CarinaStudio.MacOS;
1010

1111
/// <summary>
12-
/// Conversion between native and CLR types.
12+
/// Conversion between native and CLR types. The class is not supposed to be used directly. It is used for internal type conversion and code generation.
1313
/// </summary>
14-
static class NativeTypeConversion
14+
public static class NativeTypeConversion
1515
{
16-
// Convert from native parameter to CLR parameter.
16+
/// <summary>
17+
/// Convert from native parameter to CLR parameter.
18+
/// </summary>
1719
#if NET7_0_OR_GREATER
1820
[RequiresDynamicCode("Dynamic code generation is required for checking native type.")]
1921
#endif
@@ -59,7 +61,9 @@ static class NativeTypeConversion
5961
}
6062

6163

62-
// Convert from native value to CLR value.
64+
/// <summary>
65+
/// Convert from native value to CLR value.
66+
/// </summary>
6367
#if NET7_0_OR_GREATER
6468
[RequiresDynamicCode("Dynamic code generation is required for converting to CLR value type.")]
6569
#endif
@@ -179,8 +183,10 @@ static class NativeTypeConversion
179183
throw new NotSupportedException($"Cannot convert native value to {targetType.Name}.");
180184
}
181185

182-
183-
// Convert from Objective-C type encoding.
186+
187+
/// <summary>
188+
/// Convert from Objective-C type encoding.
189+
/// </summary>
184190
#if NET7_0_OR_GREATER
185191
[RequiresDynamicCode("Dynamic code generation is required for creating Objective-C type encoding.")]
186192
#endif
@@ -381,7 +387,9 @@ static Type FromTypeEncoding(ReadOnlySpan<char> typeEncoding, out int elementCou
381387
}
382388

383389

384-
// Get size of native value in bytes.
390+
/// <summary>
391+
/// Get size of native value in bytes.
392+
/// </summary>
385393
#if NET7_0_OR_GREATER
386394
[RequiresDynamicCode("Dynamic code generation is required for checking native type.")]
387395
#endif
@@ -410,7 +418,9 @@ public static int GetNativeValueSize(Type type)
410418
}
411419

412420

413-
// Check whether given type is the native type or not.
421+
/// <summary>
422+
/// Check whether given type is the native type or not.
423+
/// </summary>
414424
#if NET7_0_OR_GREATER
415425
[RequiresDynamicCode("Dynamic code generation is required for checking native type.")]
416426
#endif
@@ -443,8 +453,10 @@ public static bool IsNativeType(Type type)
443453
}, false);
444454
}
445455

446-
447-
// Convert from CLR parameter to native parameter.
456+
457+
/// <summary>
458+
/// Convert from CLR parameter to native parameter.
459+
/// </summary>
448460
#if NET7_0_OR_GREATER
449461
[RequiresDynamicCode("Dynamic code generation is required for checking native type.")]
450462
#endif
@@ -475,8 +487,10 @@ public static object ToNativeParameter(object? value)
475487
throw new NotSupportedException($"Cannot convert from {value.GetType().Name} to native value.");
476488
}
477489

478-
479-
// Convert from CLR object to native value.
490+
491+
/// <summary>
492+
/// Convert from CLR object to native value.
493+
/// </summary>
480494
#if NET7_0_OR_GREATER
481495
[RequiresDynamicCode("Dynamic code generation is required for converting from CLR value type.")]
482496
#endif
@@ -606,7 +620,9 @@ public static unsafe int ToNativeValue(object? obj, byte* valuePtr)
606620
}
607621

608622

609-
// Convert to corresponding native type.
623+
/// <summary>
624+
/// Convert to corresponding native type.
625+
/// </summary>
610626
#if NET7_0_OR_GREATER
611627
[RequiresDynamicCode("Dynamic code generation is required for checking native type.")]
612628
#endif
@@ -624,9 +640,14 @@ public static Type ToNativeType(Type type)
624640
}
625641

626642

627-
// Convert to Objective-C type encoding.
643+
/// <summary>
644+
/// Convert to Objective-C type encoding.
645+
/// </summary>
628646
public static string ToTypeEncoding<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] T>(int elementCount = 1) =>
629647
ToTypeEncoding(typeof(T), elementCount);
648+
/// <summary>
649+
/// Convert to Objective-C type encoding.
650+
/// </summary>
630651
public static string ToTypeEncoding(object obj)
631652
{
632653
if (obj is Type type)
@@ -635,6 +656,9 @@ public static string ToTypeEncoding(object obj)
635656
return ToTypeEncoding(obj.GetType(), array.GetLength(0));
636657
return ToTypeEncoding(obj.GetType());
637658
}
659+
/// <summary>
660+
/// Convert to Objective-C type encoding.
661+
/// </summary>
638662
public static string ToTypeEncoding([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields)] Type type, int elementCount = 1)
639663
{
640664
var isArray = type.IsArray;

0 commit comments

Comments
 (0)