public string getNameAndValue<T>(T t)
        {
            string tStr = string.Empty;
            if (t == null)
            {
                return tStr;
            }
            System.Reflection.PropertyInfo[] properties = t.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
            if (properties.Length <= 0)
            {
                return tStr;
            }
            foreach (System.Reflection.PropertyInfo item in properties)
            {
                string name = item.Name; //名称
                object value = item.GetValue(t, null);  //

                if (item.PropertyType.IsValueType || item.PropertyType.Name.StartsWith("String"))
                {
                    tStr += string.Format("{0}:{1},", name, value);
                }
                else
                {
                    getNameAndValue(value);
                }
            }
            return tStr;
        }

 

相关文章:

  • 2022-02-09
  • 2021-12-28
  • 2022-12-23
  • 2022-12-23
  • 2021-12-11
  • 2021-08-15
  • 2022-01-17
  • 2022-01-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-01-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案