I have a WinForms project, using Visual Studio 2013, DotNet Framework 4.0. How can I get a list of all of my created Forms and User Controls in the project, preferably at runtime?
EDIT: Thanks for your reply. SO for example, I want to get the FOrms and User Controls under the namespace "MyApp.Forms" and "MyApp.UserControls", how can I get the assemblies? Here's how I do it:
IEnumerable<Assembly> CurrentDomainAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("MyAppNamespace"));
foreach (Assembly a in CurrentDomainAssemblies)
{
IEnumerable<Type> AssembliesTypes = a.GetTypes().Where(t => (typeof(Form).IsAssignableFrom(t) || typeof(UserControl).IsAssignableFrom(t)) && t.IsClass);
foreach (Type t in AssembliesTypes)
{
if (t.FullName.Contains("Usercontrol"))
{
listUc.BeginUpdate();
listUc.Items.Add(t.Name);
listUc.EndUpdate();
}
if (t.FullName.Contains("Forms"))
{
listForm.BeginUpdate();
listForm.Items.Add(t.Name);
listForm.EndUpdate();
}
EDIT: This approach based on the namespace of Forms and User Controls. Is it posssible to get its filename, not its namespace?