Assembly Class
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 anAssembly which is a reusable, versionable, and self-describing buildingblock 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 aType 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 classabout which I have described in the previous article regarding"Reflection"
*Note: The exe file you are going to give asinput should be in the same folder of this exe. Give the filename withextension(.exe)If you get an error: "An unhandled exception of type'System.IO.FileNotFoundException' occurred in mscorlib.dll", it meansthat your input file name is invalid.
Code:
using System;
using System.Reflection;
using System.Collections;
namespace Assy
{
/// <summary>
/// Summary description for Class1.
/// </summary>
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();
}
}
}












No comments yet... Be the first to leave a reply!