Closed Chensem closed 1 year ago
the function aim to serialize an object to json string use System.Reflect part code snippet in c# like belowing
private static void WriteValue (object obj, JsonWriter writer, bool writer_is_private, int depth){ Type obj_type = obj.GetType (); // System.Type obj_type.GetProperties ()) ; // System.Reflection.PropertyInfo[] GetProperties(); // 0x01ff9760 obj_type. GetFields(); // System.Reflection.FieldInfo[] GetFields(); // 0x01ff9140 // public virtual object? GetValue(object? obj, object?[]? index); System.Reflection.PropertyInfo }
i want to get value from the object , but the code encounter error
il2cpp: cannot invoke method GetValue: parameter types mismatch
my snippet like belowing
const assem = Il2Cpp.Domain.assembly("Assembly-CSharp").image; const object = assem.class("ProtobufPacket.CG_CARD_MAKE").alloc(); object.method('.ctor').invoke() const type = object.tryMethod<Il2Cpp.Object>("GetType").invoke(); const properties = type.tryMethod<Il2Cpp.Array>("GetProperties" , 0).invoke(); const fields = type.tryMethod<Il2Cpp.Array>("GetFields" , 0).invoke(); for(let property of properties){ const propertyInfo = property as Il2Cpp.Object // System.Reflection.PropertyInfo console.log(propertyInfo.tryMethod("get_Name").invoke()) // System.Object GetValue(System.Object obj, System.Object[] index); // 0x0183bf4c propertyInfo.tryMethod("GetValue").invoke(object , 0); // args0 ?? } console.log(properties , fields)
console output
"has_itemnum" // property name il2cpp: cannot invoke method GetValue: parameter types mismatch // getValue failed
why object type mismatch the function GetValue args[0] ?? i am very confused , the object is inhert from System.Object . so can you help me ? thanks
reference link https://learn.microsoft.com/en-us/dotnet/api/system.reflection.propertyinfo.getvalue?view=netcore-3.1
I think you need to select the correct overload. I don't see a GetValue(System.Object, int). Converting to discussion
GetValue(System.Object, int)
the function aim to serialize an object to json string use System.Reflect part code snippet in c# like belowing
i want to get value from the object , but the code encounter error
my snippet like belowing
console output
why object type mismatch the function GetValue args[0] ?? i am very confused , the object is inhert from System.Object . so can you help me ? thanks