public static class AssemblyUtility{
private static readonly System.Reflection.Assembly[] assemblies = null;
private static readonly Dictionary<string,Type> cachedTypes;
static AssemblyUtility{
assemblies = AppDomain.CurrentDomain.GetAssemblies();
cachedTypes = new Dictionary<string,Type>();
}
public static System.Reflection.Assembly[] GetAssemblies(){
return assemblies;
}
public static Type[] GetTypes(){
List<Type> allTypes = new List<Type>();
foreach(var item in assemblies){
allTypes.AddRange(item.GetTypes());
}
return allTypes.ToArray();
}
public static Type GetType(string typeName){
if(string.IsNullOrEmpty(typeName))
Debug.LogWarning("Type Name is invalid");
Type type = null;
if(cachedTypes.TryGetValue(typeName,out type))
return type;
type = Type.GetType(typeName);
if (type != null){
cachedTypes.Add(typeName, type);
return type;
}
foreach(var item in assemblies){
type = Type.GetType(string.Format("{0}, {1}", typeName, assembly.FullName));
if (type != null){
cachedTypes.Add(typeName, type);
return type;
}
}
return null;
}
}
private static readonly System.Reflection.Assembly[] assemblies = null;
private static readonly Dictionary<string,Type> cachedTypes;
static AssemblyUtility{
assemblies = AppDomain.CurrentDomain.GetAssemblies();
cachedTypes = new Dictionary<string,Type>();
}
public static System.Reflection.Assembly[] GetAssemblies(){
return assemblies;
}
public static Type[] GetTypes(){
List<Type> allTypes = new List<Type>();
foreach(var item in assemblies){
allTypes.AddRange(item.GetTypes());
}
return allTypes.ToArray();
}
public static Type GetType(string typeName){
if(string.IsNullOrEmpty(typeName))
Debug.LogWarning("Type Name is invalid");
Type type = null;
if(cachedTypes.TryGetValue(typeName,out type))
return type;
type = Type.GetType(typeName);
if (type != null){
cachedTypes.Add(typeName, type);
return type;
}
foreach(var item in assemblies){
type = Type.GetType(string.Format("{0}, {1}", typeName, assembly.FullName));
if (type != null){
cachedTypes.Add(typeName, type);
return type;
}
}
return null;
}
}