Skip to content

Commit

Permalink
Make code more clear
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Sep 22, 2024
1 parent 4923d09 commit eb103d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions Il2CppInterop.Generator/Extensions/AsmResolverExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ namespace Il2CppInterop.Generator.Extensions;

internal static class AsmResolverExtensions
{
/// <summary>
/// Boolean, Char, or numeric type
/// </summary>
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;
}

/// <summary>
/// Boolean, Char, or numeric type
/// </summary>
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
Expand Down
4 changes: 2 additions & 2 deletions Il2CppInterop.Generator/Passes/Pass80UnstripMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eb103d0

Please sign in to comment.