بهترین راه (و شاید تنها راه) Reflection باشه.
این #C:
private static IEnumerable<UserControl> GetControls(string dllName)
{
var asm = Assembly.LoadFile(dllName);
foreach (var type in asm.GetTypes())
{
if (type.DeclaringType != typeof (UserControl))
continue;
var constructorInfo = type.GetConstructor(null);
if (constructorInfo != null)
yield return constructorInfo.Invoke(null) as UserControl;
}
}
این Linq:
private static IEnumerable<UserControl> GetControls(string dllName)
{
return from type in Assembly.LoadFile(dllName).GetTypes()
where type.DeclaringType == typeof (UserControl)
select type.GetConstructor(null)
into constructorInfo where constructorInfo != null select constructorInfo.Invoke(null) as UserControl;
}