Reflection









How do I use Reflection
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: PhotonEditor.cs Copy
975     public static System.Type[] GetAllSubTypesInScripts(System.Type aBaseClass)
976     {
977         var result = new System.Collections.Generic.List();
978         System.Reflection.Assembly[] AS = System.AppDomain.CurrentDomain.GetAssemblies();
979         foreach (var A in AS)
980         {
981             // this skips all but the Unity-scripted assemblies for RPC-list creation. You could remove this to search all assemblies in project
982             if (!A.FullName.StartsWith("Assembly-"))
983             {
984                 // Debug.Log("Skipping Assembly: " + A);
985                 continue;
986             }
987
988             //Debug.Log("Assembly: " + A.FullName);
989             System.Type[] types = A.GetTypes();
990             foreach (var T in types)
991             {
992                 if (T.IsSubclassOf(aBaseClass))
993                     result.Add(T);
994             }
995         }
996         return result.ToArray();
997     }
File name: VSCode.cs Copy
346         public static void SyncSolution()
347         {
348             System.Type T = System.Type.GetType("UnityEditor.SyncVS,UnityEditor");
349             System.Reflection.MethodInfo SyncSolution = T.GetMethod("SyncSolution", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
350             SyncSolution.Invoke(null, null);
351
352         }

Reflection 120 lượt xem

Gõ tìm kiếm nhanh...