• C#反射


             
    class UserInfo {
            public int ID { get; set; }
            public string Name { get; set; }
            public DateTime? CreateDate { get; set; }
            public decimal? Number { get; set; }
            public bool IsUse { get; set; }
        }

    UserInfo userInfo = new UserInfo(); string values = string.Empty; foreach (System.Reflection.PropertyInfo p in userInfo.GetType().GetProperties()) { if (p.PropertyType == typeof(string)) { values += string.Format("{0}='{1}', ", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(int)|| p.PropertyType == typeof(uint)) { values += string.Format("{0}={1},", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(DateTime)) { values += string.Format("{0}='{1}', ", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(decimal) || p.PropertyType == typeof(double)|| p.PropertyType == typeof(float)) { values += string.Format("{0}={1}, ", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(bool)) { values += string.Format("{0}={1}, ", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(sbyte)) { values += string.Format("{0}={1}, ", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(byte) || p.PropertyType == typeof(short) || p.PropertyType == typeof(ushort) ) { values += string.Format("{0}={1}, ", p.Name, p.GetValue(userInfo)); } if (p.PropertyType == typeof(long) || p.PropertyType == typeof(ulong)) { values += string.Format("{0}={1}, ", p.Name, p.GetValue(userInfo)); } // values +=string.Format( "{0}={1},", p.Name, p.GetValue(userInfo)); // Console.WriteLine("Name:{0} Value:{1}", p.Name, p.GetValue(userInfo)); } Console.WriteLine(values);
  • 相关阅读:
    java_web连接SQL_server详细步骤
    探索需求-设计前的质量之二
    EF三种编程方式详细图文教程(C#+EF)之Code First
    EF三种编程方式详细图文教程(C#+EF)之Model First
    EF三种编程方式详细图文教程(C#+EF)之Database First
    探索需求-设计前的质量之一
    编写有效用例之三
    编写有效用例之二
    golang 环境安装
    golang 命令详解
  • 原文地址:https://www.cnblogs.com/XiaoHongMao1/p/14442913.html
Copyright © 2020-2023  润新知