/// <summary> /// 数字数组连续时以特定分隔符省略 /// </summary> /// <param name="inputvalue"></param> /// <param name="split"></param> /// <returns></returns> public static string ToSimplifyStr(this IEnumerable <object> inputvalue, string split = "-") { StringBuilder res = new StringBuilder(); var source = inputvalue.OrderBy(it => it).ToList(); var strType = typeof(string); foreach (var item in source) { int itemValue = 0; var type = item.GetType(); if (type.IsValueType) { itemValue = ValueParse.GetInt(item.ToString()); } else if (type == strType) { itemValue = ValueParse.GetInt(item.ToString()); if (itemValue == 0) { res.AppendFormat(",{0}", item.ToString()); continue; } } else { res.AppendFormat(",{0}", itemValue); continue; } res.AppendFormat("{0}", itemValue); } return(res.ToString().TrimStart(',')); }
//Convert DataRow into T Object public static T CreateItem <T>(DataRow row) { string columnName; T obj = default(T); if (row != null) { obj = Activator.CreateInstance <T>(); foreach (DataColumn column in row.Table.Columns) { columnName = column.ColumnName; //Get property with same columnName PropertyInfo prop = obj.GetType().GetProperty(columnName); try { if (prop == null) { continue; } var rowValue = row[columnName]; if (!prop.PropertyType.IsGenericType) { if (prop.PropertyType == typeof(DateTime)) { try { rowValue = Convert.ChangeType(rowValue, prop.PropertyType); } catch { rowValue = ValueParse.GetDateTimeFromOADateNullAble(rowValue.ToString()); } } else { rowValue = Convert.ChangeType(rowValue, prop.PropertyType); } } //Get value for the column object value = (row[columnName] is DBNull) ? null : rowValue; //Set property value if (prop.CanWrite) //判断其是否可写 { prop.SetValue(obj, value, null); } } catch (Exception ex) { Logging.Log4NetHelper.Error(typeof(DataTableHelper), ex); } } } return(obj); }
/// <summary> /// Decryptors the AES from string to double. /// </summary> /// <param name="inputvalue">The inputvalue.</param> /// <returns>System.String.</returns> public static double DecryptorAesToDouble(this string inputvalue) { return(ValueParse.GetDouble(Cryptographer.DecryptorAesToDecimal(inputvalue).ToString())); }