C# 根据属性名称简单读取对象属性值

 private void SetPropertyValue(List dataColumns, object _info)
        {
            try
            {
                foreach (ConfigDataColumn tmp in dataColumns)
                {
                    if (!string.IsNullOrEmpty(tmp.ColumnCode))
                    {
                        Object v = _info.GetType().GetProperty(tmp.ColumnCode).GetValue(_info, null);
                        if (v != null)
                        {
                            tmp.ColumnValue = v.ToString();
                        }

                    }
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

 

你可能感兴趣的:(C#)