public static Func<object> GetFactory(Type t)
{
Func<object> inv;
lock (actLock)
{
if (_actCache == null) _actCache = new Dictionary<Type, Func<object>>();
if (!_actCache.TryGetValue(t,out inv))
{
#if COREFX
var constructor = t.GetConstructor(Type.EmptyTypes) ?? t.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance).First();
#else
var constructor = t.GetConstructor(Type.EmptyTypes)??t.GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null);
#endif
var body = Expression.New(constructor);
inv = Expression.Lambda<Func<object>>(body).Compile();
_actCache[t] = inv;
}
}
return inv;
}
}