C# Using Activator.CreateInstance

后端 未结 6 825
旧巷少年郎
旧巷少年郎 2020-12-04 05:42

I asked a question yesterday regarding using either reflection or Strategy Pattern for dynamically calling methods.

However, since then I have decided to change the

6条回答
  •  死守一世寂寞
    2020-12-04 06:08

    1. There's no error checking here. Are you absolutely sure that _class will resolve to a valid class? Are you controlling all the possible values or does this string somehow get populated by an end-user?
    2. Reflection is generally most costly than avoiding it. Performance issues are proportionate to the number of objects you plan to instantiate this way.
    3. Before you run off and use a dependency injection framework read the criticisms of it. =)

提交回复
热议问题