gpt4 book ai didi

c# - 如何在 C# 中获取对象的子对象?

转载 作者:行者123 更新时间:2023-11-30 20:20:26 24 4
gpt4 key购买 nike

在 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

关于c# - 如何在 C# 中获取对象的子对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36787561/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com