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

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

            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
原文地址:https://www.cnblogs.com/hofmann/p/11199227.html