Reflector

From Unify Community Wiki
Revision as of 21:00, 24 April 2008 by Opless (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Simple C# reflector, great for examining those wierd DLLs on your system :o)

Honestly, if you don't know what this does, you don't need to use it!


<csharp>

using System; using System.Collections; using System.IO; using System.Reflection;

[AttributeUsage(AttributeTargets.All)] public class MyAttribute : Attribute {

   	private string myName;
   	public MyAttribute(string name)
   	{
      		myName = name;
   	}
   	public string Name
   	{
      		get
      		{
      			return myName;
      		}

} } public class Reflector {

   public static int Main(string[] args)
   {
       if(!File.Exists(args[0]))
       {
           Console.WriteLine("Could not find file \"{0}\"", args[0]);
           return 1;
       }

       Console.WriteLine("Listing contents of assembly \"{0}\"", args[0]);

       // Open the assembly and iterate over all the principal types:

       Assembly a = Assembly.LoadFrom(args[0]);
       Type[] types = a.GetTypes();
       foreach(Type t in types)
       {
           Console.WriteLine("{0}: {1}\n", t.MemberType, t);

           // Iterate over all the members:
           MemberInfo[] mbrInfoArray = t.GetMembers();
           foreach(MemberInfo mbrInfo in mbrInfoArray)

{ Object[] attrs = mbrInfo.GetCustomAttributes(false); if(attrs.Length > 0) { foreach(object o in attrs) Console.WriteLine(" [{0}]\n", o); }

               Console.WriteLine("   {0}: {1}\n", mbrInfo.MemberType, mbrInfo);

}

       } 

       Console.WriteLine("{0} types found\n", types.Length);
       return 0;
   }

}


</csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox