12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using FCS.Common;
- using System;
- using System.Collections.Generic;
- using System.Data;
- namespace FCS.Services
- {
-
-
-
- public class BaseServices
- {
-
-
-
-
-
-
- protected T LoadData<T>(DataRow dr)
- {
- if (dr == null) return default(T);
- var t = typeof(T);
- var obj = Activator.CreateInstance(t);
- var properts = t.GetProperties();
- foreach (var pi in properts)
- {
- if (!dr.Table.Columns.Contains(pi.Name)) continue;
- pi.SetValue(obj, CommonHelper.ChangeType(dr[pi.Name], pi.PropertyType), null);
- }
- return (T)obj;
- }
-
-
-
-
-
-
- protected List<T> LoadDataList<T>(DataTable dt)
- {
- List<T> result = new List<T>();
- var t = typeof(T);
- var properts = t.GetProperties();
- object obj;
- foreach (DataRow dr in dt.Rows)
- {
- obj = Activator.CreateInstance(t);
- foreach (var pi in properts)
- {
- if (!dt.Columns.Contains(pi.Name)) continue;
- pi.SetValue(obj, CommonHelper.ChangeType(dr[pi.Name], pi.PropertyType), null);
- }
- result.Add((T)obj);
- }
- return result;
- }
- }
- }
|