利用反射来确定变量名

 public double GetValueByJp(Model.ta_ReportedData ta, int  itemid)
        {
            Type type = ta.GetType();
            string name = Sun.Extend.PublicQuery.GetItemList().Where(c => c.ID == itemid).FirstOrDefault().jp;
            PropertyInfo pi = type.GetProperties().FirstOrDefault(x => x.Name == name);
            return (double)pi.GetValue(ta, null);
        }

 

posted @ 2016-12-07 10:24  阿旭92312  阅读(137)  评论(0编辑  收藏  举报