2using System.Collections.Generic;
3using System.Linq.Expressions;
4using System.Reflection;
8 public Dictionary<string, Func<T>>
dict =
new Dictionary<string, Func<T>>();
12 Func<T> result = () =>
default(T);
17 ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
18 if (constructor !=
null)
20 result = Expression.Lambda<Func<T>>(Expression.New(constructor), Array.Empty<ParameterExpression>()).Compile();
28 Func<T> func =
dict.TryGetValue(
id);
33 Type type = Type.GetType(
id +
", " + assembly);
54 public static HashSet<string>
assemblies =
new HashSet<string>();
58 public static HashSet<Type>
modTypes =
new HashSet<Type>();
60 public static T
Create<T>(
string id,
string assembly =
"Assembly-CSharp")
62 return (T)
caches.Create<T>(id, assembly);
69 Type type = Type.GetType(
id +
", " + assembly);
Func< T > CreateDelegate(Type type)
static ClassCache< object > caches
static HashSet< string > assemblies
static T Create< T >(string id, string assembly="Assembly-CSharp")
T Create< T2 >(string id, string assembly)
static HashSet< Type > modTypes
static List< Func< string, Type > > typeLoaders
static Type LoadTypeFromGlobalNamespace(string id)
Dictionary< string, Func< T > > dict