lundi 30 mai 2022

How to call a sub class using a string variable?

So I have this simple for loop and I want to access a variable of a class

However there are multiple classes so that's how I ended up with for loop.

This is what my code looks like.

for (int i = 0; i<itemId.Length; i++)
{
    Type type = Type.GetType(" " + itemid[i]);
    object instance = Activator.CreateInstance(type);
    Debug.Log(itemResponse.data.Invoke(itemid[i]).name);
}

I am trying to access

itemResponse.data."My String".name

The classes I want to access are.

public class _1001{ }
public class _1002{ }
public class _1003{ }

and so on, is there any way I could do that?

Thanks





Aucun commentaire:

Enregistrer un commentaire