2using System.Collections.Generic;
3using System.Linq.Expressions;
4using System.Reflection;
8 public Dictionary<string, Func<T>>
dict =
new Dictionary<string, Func<T>>();
16 Func<T> func =
dict.TryGetValue(type.Name);
21 ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes);
22 if (constructor ==
null)
26 func = Expression.Lambda<Func<T>>(Expression.New(constructor), Array.Empty<ParameterExpression>()).Compile();
27 dict.Add(type.Name, func);
33 Type type = Type.GetType(
id +
", " + assembly);
38 type = Type.GetType(
id +
", " + assembly2);
52 public static HashSet<string>
assemblies =
new HashSet<string>();
54 public static T
Create<T>(
string id,
string assembly =
"Assembly-CSharp")
56 return (T)
caches.Create<T>(id, assembly);
static ClassCache< object > caches
static HashSet< string > assemblies
static T Create< T >(string id, string assembly="Assembly-CSharp")
T Create< T2 >(Type type)
Dictionary< string, Func< T > > dict