标签:bsp cmd property col SQ type setvalue stat new
public static T ReaderToEntity<T>(T objDest, SqlDataReader reader) { PropertyInfo[] property = objDest.GetType().GetProperties(); foreach (PropertyInfo p in property) { Type t = p.PropertyType; if(reader.GetValue(reader.GetOrdinal(p.Name)) != DBNull.Value) { if (t == typeof(String) || t == typeof(int) || t == typeof(int?) || t == typeof(long) || t == typeof(long?) || t == typeof(DateTime) || t == typeof(DateTime?) || t == typeof(char) || t == typeof(decimal) || t == typeof(decimal?)) p.SetValue(objDest, reader.GetValue(reader.GetOrdinal(p.Name))); } else { p.SetValue(objDest, null); } } return objDest; } =====调用 SqlDataReader reader = cmd.ExecuteReader(); if (reader == null || reader.HasRows == false) return null; reader.Read(); MileageCalResult.AddParam addParam = new MileageCalResult.AddParam(); addParam = MileageCalResult.ReaderToEntity(addParam, reader); MileageCalResult.AnalyseResult analyseResult = new MileageCalResult.AnalyseResult(); analyseResult = MileageCalResult.ReaderToEntity(analyseResult, reader); MileageCalResult obj = new MileageCalResult(addParam, analyseResult);
标签:bsp cmd property col SQ type setvalue stat new
原文地址:https://www.cnblogs.com/rogge7/p/9233329.html