private dynamic GetRefObjectClss(Type t, IReadContext r) { var pis = t.GetProperties(); dynamic nm = t.Assembly.CreateInstance(t.FullName); for (int i = 0; i < pis.Length; i++) { var pi = pis[i]; string colName = pi.Name; switch (pi.PropertyType.FullName) { case "System.String": pi.SetValue(nm, Read(r, colName), null); break; case "System.Int16": pi.SetValue(nm, Convert.ToInt16(Read(r, colName)), null); break; case "System.Int32": pi.SetValue(nm, Conv.ToInt(Read(r, colName)), null); break; case "System.Int64": pi.SetValue(nm, Convert.ToInt64(Read(r, colName)), null); break; case "System.Decimal": pi.SetValue(nm, Conv.ToDecimal(Read(r, colName)), null); break; case "System.Double": pi.SetValue(nm, Convert.ToDouble(Read(r, colName)), null); break; case "System.Float": pi.SetValue(nm, Convert.ToSingle(Read(r, colName)), null); break; //case "System.Guid": // if (row[colName] != DBNull.Value) pi.SetValue(r, (Guid)row[colName], null); // break; case "System.DateTime": pi.SetValue(nm, Conv.ToDateTime(Read(r, colName)), null); break; case "System.Char": pi.SetValue(nm, Conv.ToChar(Read(r, colName)), null); break; //case "System.Boolean": // if (row[colName] != DBNull.Value) pi.SetValue(r, (bool)row[colName], null); // break; //case "System.Byte": // if (row[colName] != DBNull.Value) pi.SetValue(r, (byte)row[colName], null); // break; } } return(nm); }
public T GetObject <T>(string key) { var t = typeof(T); var pis = t.GetProperties(); T nm = (T)Activator.CreateInstance(t); for (int i = 0; i < pis.Length; i++) { var pi = pis[i]; string colName = pi.Name; switch (pi.PropertyType.FullName) { case "System.String": pi.SetValue(nm, Read(key, colName), null); break; case "System.Int16": pi.SetValue(nm, Convert.ToInt16(Read(key, colName)), null); break; case "System.Int32": pi.SetValue(nm, Conv.ToInt(Read(key, colName)), null); break; case "System.Int64": pi.SetValue(nm, Convert.ToInt64(Read(key, colName)), null); break; case "System.Decimal": pi.SetValue(nm, Conv.ToDecimal(Read(key, colName)), null); break; case "System.Double": pi.SetValue(nm, Convert.ToDouble(Read(key, colName)), null); break; case "System.Float": pi.SetValue(nm, Convert.ToSingle(Read(key, colName)), null); break; //case "System.Guid": // if (row[colName] != DBNull.Value) pi.SetValue(r, (Guid)row[colName], null); // break; case "System.DateTime": pi.SetValue(nm, Conv.ToDateTime(Read(key, colName)), null); break; case "System.Char": pi.SetValue(nm, Conv.ToChar(Read(key, colName)), null); break; //case "System.Boolean": // if (row[colName] != DBNull.Value) pi.SetValue(r, (bool)row[colName], null); // break; //case "System.Byte": // if (row[colName] != DBNull.Value) pi.SetValue(r, (byte)row[colName], null); // break; } } return(nm); }
public static DataTable Group(DataTable tb, string group_fields, string sum_fields) { var dt = tb.Copy(); tb = tb.Copy(); string[] g_fields = group_fields.Split(','); string[] s_fields = sum_fields.Split(','); tb.DefaultView.Sort = group_fields; tb = tb.DefaultView.ToTable(); tb.Columns.Add("rows", typeof(List <DataRow>)); var tb2 = tb.Clone(); DataRow dr = null; for (int i = 0; i < tb.Rows.Count; i++) { DataRow row = tb2.NewRow(); row.ItemArray = tb.Rows[i].ItemArray; int flag = 0; if (i == 0) { flag = 1; } else { int flag2 = 0; foreach (string field in g_fields) { if (dr[field].ToString() != row[field].ToString()) { flag2 = 1; break; } } if (flag2 == 0) { if (sum_fields != "") { foreach (string field in s_fields) { dr[field] = Conv.ToDecimal(dr[field]) + Conv.ToDecimal(row[field]); } } var lst = (List <DataRow>)dr["rows"]; lst.Add(row); } else { flag = 1; } } if (flag == 1) { dr = tb2.NewRow(); var lst = new List <DataRow>(); lst.Add(row); dr["rows"] = lst; foreach (string field in g_fields) { dr[field] = row[field]; } if (sum_fields != "") { foreach (string field in s_fields) { dr[field] = row[field]; } } tb2.Rows.Add(dr); } } return(tb2); }