I'm loading custom user controls into my form using reflection. I would like all my user controls to have a "Start" and "End" method so they should all be like:
public interface IStartEnd
{
void Start();
void End();
}
public class AnotherControl : UserControl, IStartEnd
{
public void Start()
{ }
public void End()
{ }
}
I would like an interface to load through reflection, but the following obviously wont work as an interface cannot inherit a class:
public interface IMyUserControls : UserControl, IInit, IDispose
{
}
I don't see the use case, loading user controls through reflection requires knowing the type name of the control. Either use Assembly.CreateInstance if you've dynamically loaded the assembly yourself, or use the full type name with Activator.CreateInstance so that the CLR can determine what assembly needs to be loaded.
If you want to avoid specifying the user control type name then you could iterate the loaded assembly with Assembly.GetTypes() and look for a type that implements your interface. This is only going to work well if you somehow can guarantee that the assembly contains only one control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With