public static string SubToBase64String(object obj) { byte[] ba = null; try { ba = SubToBase64ByteArray(obj); if (ba == null) { return(""); } return(Convert.ToBase64String(ba, Base64FormattingOptions.None)); } catch (Exception ex) { LoggingHelper.log(ex); } finally { } return(null); }
public DataTable ArrayToDatatable(Array source, bool AddTypeColumn, string TableName, string[] properties) { DataTable dt = null; DataRow dr = null; Type t = null; PropertyInfo[] pia = null; try { if (source == null) { return(null); } dt = new DataTable(); if (TableName.Trim().Length != 0) { dt.TableName = TableName; } t = source.GetValue(0).GetType(); if (properties == null) { pia = t.GetProperties(); properties = new string[pia.Length]; for (int i = 0; i < pia.Length; i++) { properties[i] = pia[i].Name; } } //for (int i = 0; i < pia.Length; i++) // dt.Columns.Add( pia[i].Name, pia[i].PropertyType ); for (int i = 0; i < properties.Length; i++) { dt.Columns.Add(properties[i], PropertyParser.getPropertyType(properties[i], source.GetValue(0))); } if (AddTypeColumn) { dt.Columns.Add(DataHelper.DATATABLE_OBJECT_TYPE_CLASS_NAME_COLUMN, typeof(string)); } object v = null; for (int j = 0; j < source.Length; j++) { dr = dt.NewRow(); for (int i = 0; i < properties.Length; i++) { //v = pia[i].GetValue( source.GetValue( j ), null ); //v = valueForType( pia[i].PropertyType, dt.Columns[pia[i].Name].DataType, v ); v = PropertyParser.getPropertyValue(properties[i], source.GetValue(j)); dr[properties[i]] = v; } if (AddTypeColumn) { dr[DataHelper.DATATABLE_OBJECT_TYPE_CLASS_NAME_COLUMN] = t.ToString(); } dt.Rows.Add(dr); } dt.AcceptChanges(); return(dt); } catch (Exception ex) { LoggingHelper.log(ex); return(null); } finally { dr = null; t = null; if (pia != null) { Array.Clear(pia, 0, pia.Length); } pia = null; } }