请问如何射出实体类的属性和方法,用C#?

解决方案 »

  1.   


    int i = 0;
    Type t = i.GetType();
    PropertyInfo[] props = t.GetProperties();//public属性集合
    MethodInfo[] methods = t.GetMethods();//public方法集合
      

  2.   

    using System;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Reflection;namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                object o = Activator.CreateInstance(Type.GetType("WindowsApplication13.MyClass"));            MethodInfo MyMethod = o.GetType().GetMethod("Test");
                object[] obj = new object[2];
                obj[0] = "ZengHD";
                MyMethod.Invoke(o, obj);
                MessageBox.Show(obj[1].ToString());
            }
        }    public class MyClass
        {
            public void Test(string s,out string value)
            {
                value = "bbbbbbbbbbbbbbbbbbbbbb";
                MessageBox.Show(s);
            }
        }
    }
      

  3.   

    Type T = obj.GetType();
                PropertyInfo[] Proper = T.GetProperties();
                int i=0;
                foreach (PropertyInfo P in Proper)
                {
                    i++;
                    P.SetValue(obj, i.ToString(), null);
                    Console.WriteLine(P.GetValue(obj, null));
                }
      

  4.   

    public MethodInfo[] GetMethods ()
    public PropertyInfo[] GetProperties ()参看这两个方法