Geeks With Blogs
Saqib Ullah BootStrapper Know How

Many of the geeks sometime required to get a list of all form type in give assembly or a specific assembly in .Net. I have right a small code snippet that done this job for me, so I thought I must share it with you guys.

/// <summary>

/// Get list of all Form type in the give assembly.

/// </summary>

/// <param name="assemblyName">Assembly name.</param>

/// <param name="assemblyVersion">Assembly version.</param>

public void GetFormList(string assemblyName, string assemblyVersion)

 {

    //Assembly asm = Assembly.GetExecutingAssembly();

     Assembly assembly = null;

     AssemblyName asmName;

     asmName = new AssemblyName();

     asmName.Name = assemblyName; //Hello.exe

     Version v = new Version(assemblyVersion);

     asmName.Version = v;

     assembly = Assembly.Load(asmName);

     Console.WriteLine("Listing all types in {0}", assembly.FullName);

     Type[] types = assembly.GetTypes();

     foreach (Type t in types)

     {

       if (t.BaseType != null)

          {

            if (t.BaseType == typeof(System.Windows.Forms.Form))

             {

               Console.WriteLine("Form Type: {0}", t);

             }

          }

     }  

   }

 

Posted on Wednesday, January 30, 2008 2:24 AM .Net | Back to top


Comments on this post: List of all Form from an Assembly

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Saqib Ullah | Powered by: GeeksWithBlogs.net