public virtual string GetRowData(SharpObject source) { var reverseAliases = new Dictionary <string, string>(); foreach (var alias in ColumnAliases) { reverseAliases[alias.Value] = alias.Key; } RowData.Clear(); Column = 0; foreach (var column in ColumnNames) { string colname; if (!reverseAliases.TryGetValue(column.Value, out colname)) { colname = column.Value; } if (!source.ContainsKey(colname)) { AppendEmptyColumn(1); } else { // TODO: apply formatting, padding, alignment etc. here var value = (source[colname] ?? "").ToString(); AppendJustifyLeft(value); } } return(RowData.ToString()); }
public virtual SharpObject GetObject(string source) { // TODO: Add option to use packed+collapsed rows for faster reading when only a few columns are needed if (ColumnWidths.Count == 0) { return(new SharpObject()); } var column = 0; var width = ColumnWidths[column]; var sb = new StringBuilder(); var result = new SharpObject(); foreach (var c in source) { sb.Append(c); width--; if (width == 0) { var field = GetColumnName(ColumnNames[column]); var value = GetColumnValue(ColumnNames[column], sb.ToString()); if (IncludeEmptyFields || (value != null && (!(value is string) || !string.IsNullOrEmpty(value.ToString())))) { var parts = field.Split('/').ToList(); StringBuilder path = new StringBuilder(); for (int i = 0; i < parts.Count - 1; i++) { if (path.Length > 0) { path.Append("/"); } path.Append(parts[i]); var p = path.ToString(); if (!result.ContainsKey(p)) { result[p] = new SharpObject(); } } if (result.ContainsKey(field)) { result.Add(field, value); } else { result[field] = value; } } column++; if (column >= ColumnWidths.Count) { break; } width = ColumnWidths[column]; sb.Clear(); } } return(result); }
public bool ContainsKey(string key) { return(_obj.ContainsKey(key)); }