Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Polymorphism and casting object into actual type #78

Open
akintos opened this issue Dec 14, 2021 · 0 comments
Open

Polymorphism and casting object into actual type #78

akintos opened this issue Dec 14, 2021 · 0 comments

Comments

@akintos
Copy link

akintos commented Dec 14, 2021

For example,

class A : Il2CppSystem.Object { }
class B : A { }
class C : A { }

var list = new List<A>() { new A(), new B(), new C() };

In this case, when I try to get list[2].GetType(), I get typeof(A).
I was able to get actual type of it using code below

public static Type GetActualType(Il2CppSystem.Object obj)
{
    var cpptype = obj.GetIl2CppType();
    return Type.GetType(cpptype.AssemblyQualifiedName);
}

but I cannot cast object into type with cppobj.Cast<actualType>() because I cannot provide type variable into it. Is there any other way to cast il2cpp object into specific type variable in runtime?

@akintos akintos changed the title Polymorphism and get object with actual type Polymorphism and casting object with actual type Dec 14, 2021
@akintos akintos changed the title Polymorphism and casting object with actual type Polymorphism and casting object into actual type Dec 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant