[英]factory create method in C#?
I am working on an API which supplies some ActiveX COM Object and I read these warning below: 我正在使用提供一些ActiveX COM对象的API,并且在下面阅读了这些警告:
"You must use the factory “create” methods to create the COM objects in this section. Once a COM object has been created by a factory method, the COM object is tied to a corresponding TWS COM object (an instance of the COM object). Do not try to pass a COM object to another instance of a TWS COM object."
“必须在本节中使用工厂“创建”方法创建COM对象。通过工厂方法创建COM对象后,该COM对象将绑定到相应的TWS COM对象(该COM对象的实例) 。不要尝试将COM对象传递给TWS COM对象的另一个实例。”
These words come from a part of VB example on this ActiveX API. 这些词来自此ActiveX API的VB示例的一部分。 Now I am using c#, what should I do to follow this rule?
现在我正在使用c#,该怎么做才能遵循此规则?
Not knowing what any of these data types are or what you are naming these types, let's go with a data type called ActiveXType
that is defined in ApiComObject
. 不知道什么这些数据类型是什么或正在命名这些类型,让我们一起去调用的数据类型
ActiveXType
被定义ApiComObject
。
class TwsCom {
private ApiComObject apiComObject;
public TwsCom() {
apiComObject = new ApiComObject(); // create an instance, if required
}
// you might want to keep this variable type private to avoid breaking
// the rules
private ActiveXType NewActiveXType() {
return apiComObject.Create();
}
public object SomeMethod() {
ActiveXType activeX = NewActiveXType();
return activeX.SomeMethod();
}
}
This code is all very vague, but that's about the best I can do unless you'd like to provide more details. 这段代码非常模糊,但这是我能做的最好的事情,除非您想提供更多细节。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.