createinstance

Fast creation of objects instead of Activator.CreateInstance(type)

拜拜、爱过 提交于 2019-11-26 06:30:45
问题 I\'m trying to improve the performance of our application. We have a lot of Activator.CreateInstance calls that are causing some grief. We instantiate a lot of classes based on an interface (ITabDocument) and after looking around I thought of using this code: The code is no better (infact marginally slower) than using the Activator.CreateInstance code we had. public static Func<T> CreateInstance<T>(Type objType) where T : class, new() { var dynMethod = new DynamicMethod(\"DM$OBJ_FACTORY_\" +