Esempio n. 1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     Student stuObj = new Student()
     {
         Student_ID = 1,
         Student_Name = "WD",
         Student_Sex="N"
     };
     //ceshi
     GetClassInfo(stuObj);
 }
Esempio n. 2
0
        /// <summary>
        /// 根据传入的对象获取信息
        /// </summary>
        private void GetClassInfo(Student stuObj)
        {
            Type t = stuObj.GetType();

            Type t2 = stuObj.GetType();

            PropertyInfo[] pInfo = t.GetProperties();
            foreach (var item in pInfo)
            {
                string currentName = item.Name;
                object obj = item.GetValue(stuObj, null);
                t2.GetProperty(currentName).SetValue(2,obj,null);
            }
        }