C# 反射获取对象属性值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jinlingjjl/article/details/79974187
    public class ForeachClass
    {
        /// <summary>
        /// C#反射遍历对象属性
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="model">对象</param>
        public static void ForeachClassProperties<T>(T model)
        {
            Type t = model.GetType();
            PropertyInfo[] PropertyList = t.GetProperties();
            foreach (PropertyInfo item in PropertyList)
            {
                string name = item.Name;
                object value = item.GetValue(model, null);
            }
        }
    }

猜你喜欢

转载自blog.csdn.net/jinlingjjl/article/details/79974187
今日推荐