As far as I know, this instruction is only used for array initializers that have constant data. I wrote a helper method:
public static Il2CppSystem.RuntimeFieldHandle ManagedFieldToIl2CppField(System.RuntimeMethodHandle handle)
{
var methodInfo = System.Reflection.MethodInfo.GetMethodFromHandle(handle)!;
var fieldInfoField = Il2CppInteropUtils.GetIl2CppFieldInfoPointerFieldForGeneratedFieldAccessor(methodInfo)!;
var fieldInfoPtr = (nint)fieldInfoField.GetValue(null)!;
var fieldInfo = (Il2CppSystem.Reflection.FieldInfo)Il2CppObjectPool.Get(fieldInfoPtr)!; // Not sure if this is how it works
return fieldInfo.FieldHandle;
}
The unstripped code would be:
- Use ldtoken on the get method of the field accessor property. There is no C# equivalent to this, but the runtime should handle it fine.
- Call the helper method.
However, this would require either:
- Support for constant field data in type injection
- Refusing to translate ldtoken for unstripped fields
As far as I know, this instruction is only used for array initializers that have constant data. I wrote a helper method:
The unstripped code would be:
However, this would require either: