情景: 目前有两个实体类:Student,ClassInfo. public class Student { public string Name { get; set; } public string Sex { get; set; } public string Age { get; set; } } public class Classinfo { public string Subject { get; set; } public int Score { get; set; } } St…
在开发中可能会遇到这几种情况 1.EF或LINQ查询出来的匿名对象在其它地方调用不方便,又懒的手动建实体类 2.通过datatable反射实体需要先建一个类 ,头痛 3.通过SQL语句返回的实体也需要先建一个类 ,头痛 4.如果通过代码生成器要写模版,需要安装或者不想生成一堆不用的类 为了解决上面的不便之处,我封装了一个实体生成类,可以扔到程序里面任意调用 封装类: using System; using System.Collections.Generic; using System.Linq…
代码如下: 实体类: public class User implements Serializable { private static final long serialVersionUID = 1L; private String pkid; private String userName; private String passWord; private String roleID; } 遍历: public class test { public static void main(St…
实体类 public class Test { [JsonIgnore] public string GetDate { get { return GetTime.ToString("yyyy-MM-dd"); } } [JsonProperty(PropertyName = "get")] [JsonConverter(typeof(UnixDateTimeConverter))] public DateTime GetTime { get; set; } [Js…
直接贴代码吧,有需要的话,可以根据自己的需要修改部分代码: public BigDecimal getByAttributeName(ThmdGwqriR thmdGwqriR, String attributeName){ for (Field field : thmdGwqriR.getClass().getDeclaredFields()) { field.setAccessible(true); try{ if (attributeName.toLowerCase().equals(fi…
using System.Reflection; Type t = obj.GetType();//获得该类的Type foreach (PropertyInfo pi in t.GetProperties()){ var name = pi.Name;//获得属性的名字,后面就可以根据名字判断来进行些自己想要的操作 var value = pi.GetValue(obj, null);//用pi.GetValue获得值 var type = value?.GetType() ?? typeof…