1234567891011121314151617181920212223242526272829 |
- using System;
- using System.Reflection;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public static class ReflectiveEnumerator
- {
- static ReflectiveEnumerator() { }
- public static IEnumerable<T> GetEnumerableOfType<T>(params object[] constructorArgs) where T : class, IComparable<T>
- {
- List<T> objects = new List<T>();
- var assemblies = AppDomain.CurrentDomain.GetAssemblies();
- foreach (var assembly in assemblies)
- {
- foreach (Type type in assembly.GetTypes()
- .Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
- {
- objects.Add((T)Activator.CreateInstance(type, constructorArgs));
- }
- }
- //foreach (var item in objects) Debug.Log(item);
- objects.Sort((x,y) => String.Compare(x.ToString(), y.ToString()));
- //objects.Sort();
- return objects;
- }
- }
|