Source Viewer:  assyq.cs

Font Size:
Arrays.asmx  asmx2wsdl.cs  assyq.cs  hash.cs  ListTest.cs  ListTest.VB.vb  MyIpConfig.cs  Printer.cs  Printers.aspx  PrivateReflection2.cs  RegexVerifier.cs  rtfcontrol.cs  wakeup.cs 
AES-example  books  CustomTabControl  data  emacs  Embedded Resources  ftp  interop  itext  Java  js-unzip  misc  MQ  MSOffice  Mvc.HelloWorld  perl  streams  Tar  timer  web-services  WPF  xml  xml-serialization  xml1  zips 

// AssemblyInterrogator.cs // // (down)loads the specified assembly and interrogates it // for name, version, culture, etc. // // for some background, see: // http://msdn.microsoft.com/library/en-us/dnadvnet/html/vbnet10142001.asp // // (c) Ionic Shade // // Thu, 24 Apr 2003 15:31 // using System; using System.Reflection; namespace dinoch.demo { public class AssemblyHost : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Button btnLoad; public AssemblyHost() { InitializeComponent(); } protected override void Dispose( bool disposing ) { base.Dispose( disposing ); } private void InitializeComponent() { this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.textBox1 = new System.Windows.Forms.TextBox(); this.panel1 = new System.Windows.Forms.Panel(); this.btnLoad = new System.Windows.Forms.Button(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // textBox1 // this.textBox1.BackColor = System.Drawing.Color.White; this.textBox1.Location = new System.Drawing.Point(2, 4); this.textBox1.Name = "richTextBox1"; this.textBox1.Size = new System.Drawing.Size(280, 20); this.textBox1.TabIndex = 0; this.textBox1.Text = "http://www.winisp.net/cheeso/dl/rtfc2.dll"; // // richTextBox1 // this.richTextBox1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.richTextBox1.BackColor = System.Drawing.Color.White; this.richTextBox1.Location = new System.Drawing.Point(2, 38); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(320, 200); this.richTextBox1.TabIndex = 3; this.richTextBox1.Text = ""; // // panel1 // this.panel1.BackColor = System.Drawing.Color.LightGray; this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] { this.textBox1, this.btnLoad}); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(320, 32); this.panel1.TabIndex = 9; // // btnLoad // this.btnLoad.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.btnLoad.Location = new System.Drawing.Point(288, 4); this.btnLoad.Name = "btnLoad"; this.btnLoad.Size = new System.Drawing.Size(48, 24); this.btnLoad.TabIndex = 1; this.btnLoad.Text = "Load"; this.btnLoad.Click += new System.EventHandler(this.Load_Click); // // this // this.BackColor = System.Drawing.Color.LightGray; this.Controls.AddRange(new System.Windows.Forms.Control[] { this.panel1, this.richTextBox1}); this.Name = "Interrogator for .NET Assemblies"; this.Resize += new System.EventHandler(this.Form_Resize); this.Size = new System.Drawing.Size(520, 380); this.Text = "Interrogator for .NET Assemblies"; this.Load += new System.EventHandler(this.Form_Load); this.panel1.ResumeLayout(false); this.ResumeLayout(false); } /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { System.Windows.Forms.Application.Run(new AssemblyHost()); } private void Form_Resize(object sender, System.EventArgs e) { this.richTextBox1.Size = new System.Drawing.Size(this.Size.Width - 16,this.Size.Height - this.panel1.Height - 46); this.panel1.Size = new System.Drawing.Size(this.Size.Width - 12,this.panel1.Size.Height); this.textBox1.Size = new System.Drawing.Size(this.Size.Width - 12 - this.btnLoad.Size.Width - 12, 20); this.btnLoad.Location = new System.Drawing.Point(this.Size.Width - 12 - this.btnLoad.Size.Width, 4); } private void Form_Load(object sender, System.EventArgs e) { } private void Append(string s) { this.richTextBox1.Text+= s; } private Type ReferencedType(Type t) { return (t.HasElementType) ? ReferencedType(t.GetElementType()) : t ; } private string TypeStringWithInterfaces(Type t1) { System.Text.StringBuilder result= new System.Text.StringBuilder(t1.ToString()); Type t= ReferencedType(t1); Type[] it= t.GetInterfaces(); if (it.Length > 0 ) { int j=0; for (int i=0; i < it.Length; i++) { if ((t.BaseType!=null) && !(it[i].IsAssignableFrom(t.BaseType))) { if (j==0) result.Append(" : "); else result.Append(", "); result.Append(it[i].ToString()); j++; } } } return result.ToString(); } private void BuildClassHierarchy(System.Type t, System.Collections.Stack s) { s.Push(t); if (t.BaseType != null) BuildClassHierarchy(t.BaseType, s); } public string ClassHierarchy(System.Type t) { if (t == null) return ""; System.Collections.Stack classHierarchy= new System.Collections.Stack(); BuildClassHierarchy(t, classHierarchy); // int c= classHierarchy.Count; System.Text.StringBuilder sb= new System.Text.StringBuilder(); sb.Append("Hierarchy:\n"); int i=0; while (classHierarchy.Count != 0) { for (int j = 0; j < i+1; j++) sb.Append(" "); sb.Append("+ "); //sb.Append(TypeStringWithInterfaces((Type)classHierarchy.Pop())).Append("\n"); sb.Append(((Type)classHierarchy.Pop()).FullName).Append("\n"); i++; } return sb.ToString() ; } private void Load_Click(object sender, System.EventArgs e) { this.richTextBox1.Text= ""; try { //Download the assembly from a web server over HTTP string sLocation= this.textBox1.Text; Assembly a= Assembly.LoadFrom(sLocation); this.Append("Assembly info:\ncodebase: "); this.Append(a.CodeBase.ToString()); this.Append("\nName: "); this.Append(a.GetName().Name); this.Append("\nVersion: "); this.Append(a.GetName().Version.ToString()); this.Append("\nFullName: "); this.Append(a.FullName); this.Append("\nRuntimeVersion: "); this.Append(a.ImageRuntimeVersion); this.Append("\nLocation :\n "); this.Append(a.Location.ToString()); // interrogate available types here... System.Type[] types= a.GetTypes(); this.Append("\nTypes (count=" + types.Length + ") :"); foreach (System.Type t in types) { this.Append("\n "); if ((t.Attributes & System.Reflection.TypeAttributes.Public) != 0) this.Append("public "); if ((t.Attributes & System.Reflection.TypeAttributes.Sealed) != 0) this.Append("sealed "); if ((t.Attributes & System.Reflection.TypeAttributes.Serializable) != 0) this.Append("serializable "); if ((t.Attributes & System.Reflection.TypeAttributes.ClassSemanticsMask) == System.Reflection.TypeAttributes.Interface) this.Append("interface "); else this.Append("class "); this.Append(TypeStringWithInterfaces(t)); this.Append("\n"); this.Append(ClassHierarchy(t)); } // interrogate permissions here... } catch (Exception exc) { this.richTextBox1.Text= "Exception:\n" + exc.ToString(); } } } }

The srcview page has been enjoyed 291584 times since 18 September 2003