By Rajadurai .P
This article helps you to extract the details of all the types in any code from its .exe file.
We can accomplish this using Assembly class in .Net framework.
Assembly is a public class. It defines an Assembly which is a reusable, versionable, and self-describing building block of a common language runtime application.
We need to associate an Assembly local variable with a .exe file. This can be done using the "LoadFrom" method of Assembly class
We can collect all the types associated with that assembly in a Type array(Type[]) using "GetTypes" method of the Assembly class.
We can recursively collect the details of all the types inside implemented inside some other types.
We can get the details of all the types using MemberInfo class about which I have described in the previous article regarding "Reflection"
*Note: The exe file you are going to give as input should be in the same folder of this exe. Give the filename with extension(.exe)
If you get an error: "An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll", it means that your input file name is invalid.
Code:
using System;
using System.Reflection;
using System.Collections;
namespace Assy
{
///
/// Summary description for Class1.
///
class Class1
{
static void Main(string[] args)
{
int i;
string s;
string opt = "y";
while((opt == "y")||(opt == "Y"))
{
Console.Write("Enter the .exe file (with extension) : ");
s = Console.ReadLine();
Console.WriteLine("");
Assembly a = Assembly.LoadFrom(s);
Type[] tArr = a.GetTypes();
foreach(Type t in tArr)
{
Console.WriteLine(t.FullName);
MemberInfo[] m = t.GetMembers();
foreach(MemberInfo m1 in m)
{
Console.WriteLine(m1.Name);
}
Console.WriteLine("---------------------");
}
Console.Write("Do You want to test again? (y/n) : ");
opt = Console.ReadLine();
}
i = Console.Read();
}
}
}