C# 反射

using System.Data;
using System.Reflection;


DataTable dt = new DataTable();

            var type = typeof(Customer);


            foreach (var info in type.GetProperties())
            {
                dt.Columns.Add(new DataColumn(info.Name, info.PropertyType));
            }


            try
            {
                for (int i = 0; i < CustomerOperator.customer.Length; i++)
                {
                    DataRow dr = dt.NewRow();
                    foreach (PropertyInfo property in type.GetProperties())
                    {
                        dr[property.Name] = property.GetValue(CustomerOperator.customer[i], null);
                    }


                    dt.Rows.Add(dr);
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                throw new NotImplementedException();
            }
            finally
            {
                
            }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章