且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从VBA访问.NET通用对象

更新时间:2021-12-18 04:42:15

我发现本文描述了一个丑陋的骇客-通过反思调用所有内容.由于仍返回一个通用值作为对象,因此反射应该可以工作,但会造成以下问题:1)速度慢,2)容易出错,3)调用非常不便.

I found this article describing an ugly hack - calling everything through reflection. Since a generic value is still returned as an object, reflection should work, but will be 1) slow, 2) error prone, and 3) very inconvenient to call.

如文章所示,我将使用具有以下签名的实用程序方法:

As the article shows, I would use utility methods with the following signatures:

public object GetProperty(object Instance, string Property)
public object InvokeMethod(object Instance, string Method)
public object InvokeMethod_OneParm(object Instance, string Method, object Parm1)
public object InvokeMethod_TwoParms(object Instance, string Method, object Parm1, object Parm2)
public void SetProperty(object Instance, string Property, object Value)

丑陋,但可行.