I have a following problem I want to solve ellegantly:
public interface IMyclass
{
}
public class A
{
public void Init(IMyclass class){?}
public IMyclass CreateMyClass(){?}
}
At the start of the system I want to define dynamic type of IMyClass by using Init() and during the run of the system i would like to create new instances of the type I defined at init.
Notes:
1. IMyclass must be interface
2. The dynamic type of IMyclass known only at init (i have no constructor after 🙂 )
3. I could do it using a reflection or definition method clone at IMyclass is there any better solutions?
Thank you.
You could pass a provider into
class AOr maybe with a constructor delegate
Note that both of these examples will blow up if
Inithas not been called beforeCreateMyClass, you would need some checking or better is doing your init in the constructor.Have I understood the question correctly?