public static T FromTsvRow <T>(this string tsvString) where T : new() { if (string.IsNullOrEmpty(tsvString)) { return(default(T)); } var tsvValues = tsvString.Split(Char.Parse(TsvConfig.Delimiter)); var propsDic = TsvFormatter.PropertyNamesDictionary(typeof(T)); var obj = new T(); var type = typeof(T); var index = 0; foreach (var p in propsDic.OrderBy(x => x.Key)) { var value = TsvConfig.DeserialzeFnDictionary.ContainsKey(p.Value.Value) ? TsvConfig.DeserialzeFnDictionary[p.Value.Value](tsvValues[index]) : TsvFormatter.GetValue(tsvValues[index], p.Value.Value); type.GetProperty(p.Value.Key).SetValue(obj, value); index++; } return(obj); }
public static string ToTsvHeaderRow <T>(this T objToSerialize) where T : class { return(TsvFormatter.GetHeaderRow(typeof(T))); }
public static string ToTsv <T>(this IEnumerable <T> collectionToSerialize, bool includeHeaders = true) where T : class { var data = string.Join("", collectionToSerialize.Select(x => x.ToTsvDataRow())); return(includeHeaders ? string.Concat(TsvFormatter.GetHeaderRow(typeof(T)), data) : data); }
public static string ToTsvDataRow <T>(this T objToSerialize) where T : class { var properties = TsvFormatter.GetSerializablePropertiesInOrder(typeof(T)); return(TsvFormatter.GetTsvRow(properties, objToSerialize)); }