c#类属性反射成字典或其他集合


[Test]
        public void Test()
        {
            var result = new Dictionary<string, string>();
            var creditCard = new PbocCreditCard()
            {
                rh_bad_credit_limit = 100
            };
            if (creditCard != null)
            {
                result = creditCard.GetType().GetProperties().ToDictionary(p => p.Name, p => p.GetValue(creditCard)?.ToString());
            }

            var dt = new DateTime();
            var dic = dt.GetType().GetProperties().ToDictionary(q => q.Name, q => q.GetValue(dt).ToString());
            var json = JsonConvert.SerializeObject(dic);

            json = JsonConvert.SerializeObject(result);

        }
C