简体   繁体   中英

factory create method in C#?

I am working on an API which supplies some ActiveX COM Object and I read these warning below:

"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."

These words come from a part of VB example on this ActiveX API. Now I am using c#, what should I do to follow this rule?

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM