现在的位置: 首页 > 综合 > 正文

反射属性的名称与值

2012年06月22日 ⁄ 综合 ⁄ 共 560字 ⁄ 字号 评论关闭
    public class refInfo
    {
        public int ID { getset; }
        public string Name { getset; }
        public int Sex { getset; }
        public string Adress { getset; }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            System.Reflection.PropertyInfo[] infos = this.GetType().GetProperties();
            foreach (var x in infos)
            {
                sb.Append(string.Format("{0}:{1};", x.Name, x.GetValue(thisnull)));
            }
            return sb.ToString();
        }
    }

抱歉!评论已关闭.