Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant