请问如何反射实体
请问如何射出实体类的属性和方法,用C#?
[解决办法]
int i = 0;Type t = i.GetType();PropertyInfo[] props = t.GetProperties();//public属性集合MethodInfo[] methods = t.GetMethods();//public方法集合
[解决办法]
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); } }}