1. using UnityEngine;
    2. using System;
    3. using System.Reflection;
    4. public class NewBehaviourScript : MonoBehaviour
    5. {
    6. // Start is called before the first frame update
    7. void Start()
    8. {
    9. Test1();
    10. }
    11. public string TestMethod<T>()
    12. {
    13. Debug.Log($"TestMethod {typeof(T)}");
    14. return ">";
    15. }
    16. class Person
    17. {
    18. public string Name { get; set; }
    19. public int id { get; set; }
    20. }
    21. public void Test1()
    22. {
    23. Type targetType = typeof(Person);
    24. //NewBehaviourScript.TestMethod<targetType>();
    25. MethodInfo method = typeof(NewBehaviourScript).GetMethod("TestMethod").MakeGenericMethod(targetType);
    26. Debug.Log(method.Invoke(this, null));
    27. }
    28. }