In this case, DataRow is converted to a single entity, and dataTable is converted to a List generic type, which supports time format conversion.
The following methods are all extension methods. The extension method must be written in a static class, and the method should also be static.
- Medium
- (The first parameter type is also called the extension type, that is, the method is used to expand this type)
1. Convert DataRow to an object
T ToModel<T>( DataRow dr) T : , ToModel<T>(dr,
2. Convert DataRow to an object and set the time format conversion.
T ToModel<T>( DataRow dr, dateTimeToString) T : , (dr != ToList<T>
3. convert a able to an object
List<T> ToList<T>( DataTable dt, dateTimeToString) T : , <T> list = List<T> (dt != <PropertyInfo> infos = List<PropertyInfo><PropertyInfo>((T).GetProperties(), p => (dt.Columns.Contains(p.Name) == <T>
4. Conversion implementation code
SetList<T>(List<T> list, List<PropertyInfo> infos, DataTable dt, dateTimeToString) T : , (DataRow dr = => (dr[p.Name] != DBNull.Value) tempValue = (dr[p.Name].GetType() == (DateTime) && dateTimeToString == )=); }