C# 反射遍历对象所有属性

        [TestMethod]
        public void Test6()
        {
            List repaymentList = new List();

            StringBuilder msg = new StringBuilder();
            RepaymentRecord entity = new RepaymentRecord();
            entity.Month1 = "100";
            entity.Month18 = "900";
            entity.Month24 = "322";
            foreach (PropertyInfo p in entity.GetType().GetProperties())
            {
                msg.AppendFormat("{0},{1}", p.Name, p.GetValue(entity));
            }
            var result = msg;
            Assert.IsNotNull(result);
        }
View Code

 

你可能感兴趣的:(C# 反射遍历对象所有属性)