在VB.net中,此代码可以:
Dim oPS as Object= CreateObject("Photoshop.Application.10")
Dim oDocument as Object= oPS.ActiveDocument
但是在C#中,此代码会发生错误:
Object oPS = COMCreateObject("Photoshop.Application.10");
Object oDocument = oPS.ActiveDocument;
建立时发生错误
Error 2 'object' does not contain a definition for 'ActiveDocument' and no extension method 'ActiveDocument' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
如何在C#(相同的vb.net)中获取对象的子对象?
使用dynamic
关键字代替object
:
dynamic oPS = COMCreateObject("Photoshop.Application.10");
dynamic oDocument = oPS.ActiveDocument;
MSDN参考在这里:https : //msdn.microsoft.com/en-us/library/dd264736.aspx
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句