c#写一个控制台程序,接受一个命令行参数,参数是一个类名(比如System.Object),然后把类名和GUID,公共方法的数量以及这些方法的一个列表,保护方法的数量以及列表,这些方法列表包含方法名,返回类型和参数类型,一个这个类包含的assembly的介绍,包括名字,版本和exported类型。输出格式大概是:
Type name : System.Object
GUID : 81c5fe01-027c-3e1c-98d5-da9c9862aa21
****** The number of public methods is 1 ******
The name of the method is GetHashCode.
Return type: System.Int32
Takes no parameters
****** End of Methods ******
****** The number of protected methods is 1 ******
The name of the method is Finalize.
Return type: System.Void
Takes no parameters
****** End of Methods ******
****** Assembly Information ******
Assembly name : mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Exported Types Count : 872谁能帮我做一做这个吗?非常感谢。

解决方案 »

  1.   

    反射例子很多,网上google搜索一下可以下载到一大把
      

  2.   

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Reflection;namespace Reflection
    {
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.Label label2;
    private System.Windows.Forms.Label label3;
    private System.Windows.Forms.Label label4;
    private System.Windows.Forms.ComboBox cbo;
    private System.Windows.Forms.ListBox l3;
    private System.Windows.Forms.ListBox l2;
    private System.Windows.Forms.ListBox l1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null; public Form1()
    {
    //
    // Required for Windows Form Designer support
    //
    InitializeComponent(); //
    // TODO: Add any constructor code after InitializeComponent call
    //
    } /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
    this.button1 = new System.Windows.Forms.Button();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.cbo = new System.Windows.Forms.ComboBox();
    this.l2 = new System.Windows.Forms.ListBox();
    this.l3 = new System.Windows.Forms.ListBox();
    this.l1 = new System.Windows.Forms.ListBox();
    this.label1 = new System.Windows.Forms.Label();
    this.label4 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // button1
    // 
    this.button1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.button1.Location = new System.Drawing.Point(240, 72);
    this.button1.Name = "button1";
    this.button1.TabIndex = 4;
    this.button1.Text = "List";
    this.button1.Click += new System.EventHandler(this.button1_Click);
    // 
    // label2
    // 
    this.label2.Font = new System.Drawing.Font("Comic Sans MS", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.label2.Location = new System.Drawing.Point(48, 112);
    this.label2.Name = "label2";
    this.label2.TabIndex = 6;
    this.label2.Text = "Methods";
    this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // label3
    // 
    this.label3.Font = new System.Drawing.Font("Comic Sans MS", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.label3.Location = new System.Drawing.Point(216, 112);
    this.label3.Name = "label3";
    this.label3.TabIndex = 7;
    this.label3.Text = "Interfaces";
    this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // cbo
    // 
    this.cbo.DropDownWidth = 121;
    this.cbo.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.cbo.Items.AddRange(new object[] {
     "System.String",
     "System.Int32",
     "System.Console"});
    this.cbo.Location = new System.Drawing.Point(72, 72);
    this.cbo.Name = "cbo";
    this.cbo.Size = new System.Drawing.Size(121, 21);
    this.cbo.TabIndex = 3;
    // 
    // l2
    // 
    this.l2.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.l2.Location = new System.Drawing.Point(184, 136);
    this.l2.Name = "l2";
    this.l2.Size = new System.Drawing.Size(160, 43);
    this.l2.TabIndex = 1;
    // 
    // l3
    // 
    this.l3.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.l3.Location = new System.Drawing.Point(352, 136);
    this.l3.Name = "l3";
    this.l3.Size = new System.Drawing.Size(136, 43);
    this.l3.TabIndex = 0;
    // 
    // l1
    // 
    this.l1.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.l1.Location = new System.Drawing.Point(8, 136);
    this.l1.Name = "l1";
    this.l1.Size = new System.Drawing.Size(168, 43);
    this.l1.TabIndex = 2;
    // 
    // label1
    // 
    this.label1.Location = new System.Drawing.Point(24, 16);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(456, 40);
    this.label1.TabIndex = 5;
    this.label1.Text = "Select from the Combo box, the class about which you would like to see the detail" +
    "s. ";
    // 
    // label4
    // 
    this.label4.Font = new System.Drawing.Font("Comic Sans MS", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.label4.Location = new System.Drawing.Point(376, 112);
    this.label4.Name = "label4";
    this.label4.TabIndex = 8;
    this.label4.Text = "Fields";
    this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    // 
    // Form1
    // 
      

  3.   

    this.AutoScaleBaseSize = new System.Drawing.Size(7, 19);
    this.ClientSize = new System.Drawing.Size(496, 197);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
      this.label4,
      this.label3,
      this.label2,
      this.label1,
      this.button1,
      this.cbo,
      this.l1,
      this.l2,
      this.l3});
    this.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void button1_Click(object sender, System.EventArgs e)
    {
    l1.Items.Clear();
    l2.Items.Clear();
    l3.Items.Clear();
    string s = cbo.Text;
    switch (s)
    {
    case "System.String": GetStringInfo();break;
    case "System.Int32" :GetIntInfo();break;
    case "System.Console" :GetConsoleInfo();break;
    default : break;
    };
    }
    public void GetStringInfo()
    {
    Type t = typeof(System.String);
    MemberInfo[] m = t.GetMethods();
    foreach (MemberInfo m1 in m)
    {
    l1.Items.Add(m1);
    }
    MemberInfo[] i = t.GetInterfaces();
    foreach(MemberInfo i1 in i)
    {
    l2.Items.Add(i1);
    }
    MemberInfo[] f = t.GetFields();
    foreach(MemberInfo f1 in f)
    {
    l3.Items.Add(f1);
    }
    return;
    }
    public void GetIntInfo()
    {
    Type t = typeof(System.Int32);
    MemberInfo[] m = t.GetMethods();
    foreach (MemberInfo m1 in m)
    {
    l1.Items.Add(m1);
    }
    MemberInfo[] i = t.GetInterfaces();
    foreach(MemberInfo i1 in i)
    {
    l2.Items.Add(i1);
    }
    MemberInfo[] f = t.GetFields();
    foreach(MemberInfo f1 in f)
    {
    l3.Items.Add(f1);
    }
    return;
    }
    public void GetConsoleInfo()
    {
    Type t = typeof(System.Console);
    MemberInfo[] m = t.GetMethods();
    foreach (MemberInfo m1 in m)
    {
    l1.Items.Add(m1);
    }
    MemberInfo[] i = t.GetInterfaces();
    foreach(MemberInfo i1 in i)
    {
    l2.Items.Add(i1);
    }
    MemberInfo[] f = t.GetFields();
    foreach(MemberInfo f1 in f)
    {
    l3.Items.Add(f1);
    }
    return;
    }
    }
    }
      

  4.   

    interoperability (无痕)   这个对我来说没问题
    你查以下   CreateInstance()  MSDN里有说明和事例
      

  5.   

    谁能帮我写一个吗?是我一个作业,但是我之前只用过JAVA,顺便回 eglic(圪圪),反射可以动态扩展你的程序,而且集成开发环境也需要反射来知道类的信息,这是JAVA里的。
    我这个程序只需要接受命令行参数,输出也是到console。ljc_zy(彷徨) 大哥给的好像是GUI的,虽然更好但是不符合我作业要求,不好意思了。
    我因为还有其他三个作业,j2me,unix下c编程,web service,所以实在没时间看.net的了,各位大虾帮帮忙,应该不难的,我用java写过。谢谢了。