CreateObject equivalent for C# 4, dynamic keyword, and late binding?

前端 未结 1 1495
星月不相逢
星月不相逢 2021-02-14 06:47

How do I create a dynamic COM/OLE/ActiveX object in C# 4.0 from a program identifier or ProgID (such as \"Word.Application\") without referencing a library?

In C# 3.5 I\

相关标签:
1条回答
  • 2021-02-14 07:23

    What's wrong with

    dynamic myTypeInstance = Activator.CreateInstance(Type.GetTypeFromProgID(typeName, true));
    

    ?

    If it's a known type name, there's also

    dynamic myTypeInstance = Activator.CreateInstance("typeName", "assemblyName");
    
    0 讨论(0)
提交回复
热议问题