Is it possible to use a c# object initializer with a factory method?

前端 未结 7 1605
离开以前
离开以前 2020-12-25 13:06

I have a class with a static factory method on it. I want to call the factory to retrieve an instance of the class, and then do additional initialization, preferablly via c#

相关标签:
7条回答
  • 2020-12-25 13:32

    No, the object initializer can only be used on a call to "new" with the constructor. One option might be to add some additional args to your factory method, to set those values at object creation inside the factory.

    MyClass instance = MyClass.FactoryCreate(int someValue, string otherValue);
    
    0 讨论(0)
提交回复
热议问题