activator

How to access Microsoft Word existing instance using late binding

一笑奈何 提交于 2019-11-26 12:46:24
问题 i am developing some code in c# where i will be interacting with Microsoft Word. I want to be able to have the option of re-using an existing instance or as an alternative creating a new instance. Keeping in mind i want to do all of this using LATE BINDING... it is safe to say i have figured out how to get things working when creating a new instance.. i just call Activator.CreateInstance etc.. The problem i am having is how do i reuse an existing instance, for example, Word is already open

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_\" +

How to dynamically create generic C# object using reflection? [duplicate]

六眼飞鱼酱① 提交于 2019-11-26 01:27:40
问题 This question already has answers here : Pass An Instantiated System.Type as a Type Parameter for a Generic Class (6 answers) Closed 5 years ago . In C# I have the following object: public class Item { } public class Task<T> { } public class TaskA<T> : Task<T> { } public class TaskB<T> : Task<T> { } I want to dynamically create TaskA or TaskB using C# reflection ( Activator.CreateInstance ). However I wouldn\'t know the type before hand, so I need to dynamically create TaskA based on string