From eb103d05b3fbec16d876485ed162462d91062291 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Sun, 22 Sep 2024 10:08:19 -0700 Subject: [PATCH] Make code more clear --- .../Extensions/AsmResolverExtensions.cs | 14 ++++++++++++-- .../Passes/Pass80UnstripMethods.cs | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs b/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs index 452168b5..f034a31a 100644 --- a/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs +++ b/Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs @@ -7,10 +7,20 @@ namespace Il2CppInterop.Generator.Extensions; internal static class AsmResolverExtensions { + /// + /// Boolean, Char, or numeric type + /// public static bool IsPrimitive(this TypeSignature type) { - //https://github.com/jbevain/cecil/blob/8e1ae7b4ea67ccc38cb8db3ded6802643109ffd7/Mono.Cecil/TypeReference.cs#L286 - return type is CorLibTypeSignature { ElementType: >= ElementType.Boolean and <= ElementType.R8 or ElementType.I or ElementType.U }; + return (type as CorLibTypeSignature)?.ElementType.IsPrimitive() ?? false; + } + + /// + /// Boolean, Char, or numeric type + /// + public static bool IsPrimitive(this ElementType elementType) + { + return elementType is >= ElementType.Boolean and <= ElementType.R8 or ElementType.I or ElementType.U; } public static TypeSignature GetElementType(this TypeSignature type) => type switch diff --git a/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs b/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs index 1e5fa868..f1348752 100644 --- a/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs +++ b/Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs @@ -262,8 +262,8 @@ private static PropertyDefinition GetOrCreateProperty(MethodDefinition unityMeth if (targetAssemblyName.EndsWith(".dll")) targetAssemblyName = targetAssemblyName.Substring(0, targetAssemblyName.Length - 4); - if (useSystemCorlibPrimitives && unityType is CorLibTypeSignature { ElementType: not ElementType.TypedByRef and not ElementType.Object } corlibType) - return imports.Module.CorLibTypeFactory.FromElementType(corlibType.ElementType); + if (useSystemCorlibPrimitives && unityType.IsPrimitive() || unityType.ElementType is ElementType.String or ElementType.Void) + return imports.Module.CorLibTypeFactory.FromElementType(unityType.ElementType); if (targetAssemblyName == "UnityEngine") foreach (var assemblyRewriteContext in context.Assemblies)