Skip to content

Commit c79bc4c

Browse files
ds5678SamboyCoding
authored andcommitted
Add implicit conversion operator from Il2CppVariableWidthIndex<T> to int
1 parent 12c8b44 commit c79bc4c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

LibCpp2IL/Metadata/Il2CppVariableWidthIndex.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Threading;
33

44
namespace LibCpp2IL.Metadata;
@@ -14,7 +14,7 @@ namespace LibCpp2IL.Metadata;
1414
/// - v105 extends this to MethodIndex
1515
/// </summary>
1616
/// <typeparam name="T"></typeparam>
17-
public record struct Il2CppVariableWidthIndex<T> where T : ReadableClass
17+
public readonly record struct Il2CppVariableWidthIndex<T> where T : ReadableClass
1818
{
1919
//Statics here are per-T.
2020
private static int widthForThisTypeOnCurrentApplication = -1; // -1 means "not yet determined"
@@ -27,7 +27,7 @@ public record struct Il2CppVariableWidthIndex<T> where T : ReadableClass
2727
/// </summary>
2828
private static object readSessionLock = new object();
2929

30-
private int value;
30+
private readonly int value;
3131

3232
public bool IsNull => value < 0; //The exact value of the "null" index depends on the width
3333
public bool IsNonNull => !IsNull;
@@ -102,4 +102,6 @@ internal static void EndReadSession()
102102
widthForThisTypeOnCurrentApplication = -1;
103103
Monitor.Exit(readSessionLock);
104104
}
105+
106+
public static implicit operator int(Il2CppVariableWidthIndex<T> index) => index.value;
105107
}

0 commit comments

Comments
 (0)