private string GetCsvStringFromT(T t) { StringBuilder csvStringBuilder = new StringBuilder(string.Empty); try { var reflectedList = _reflectionHelper.GetReflectedPropertyInfo(t); /*Iterate the column from the Mapper and find the matching columns from the current row and extract only the columns specifed * in mapper and ignore other columns*/ bool firstColumn = true; foreach (string propName in PropertyNameToPersist) { IReflectedPropertyInfo propInfo = reflectedList.FirstOrDefault(i => i.PropertyName.Trim().ToUpper() == propName.Trim().ToUpper()); string columnData = GetCsvColumnDataFromPropertyInfo(propInfo); csvStringBuilder.Append(firstColumn ? columnData : "," + columnData); firstColumn = false; } } catch (Exception ex) { _logger.LogError($"Some error occured in transforming an object into CSV.n{ex.Message}\n{ex.StackTrace}"); LogAndThrowError($"Some error occured in transforming an object into CSV", ErrorCodes.ObjectToCsvConvertionError); } return(csvStringBuilder.ToString() + Environment.NewLine); }
private string GetCsvStringFromT(T t) { StringBuilder csvStringBuilder = new StringBuilder(string.Empty); var reflectedList = _reflectionHelper.GetReflectedPropertyInfo(t); /*Iterate the column from the Mapper and find the matching columns from the current row and extract only the columns specifed * in mapper and ignore other columns*/ bool firstColumn = true; foreach (string propName in PropertyNameToPersist) { IReflectedPropertyInfo propInfo = reflectedList.FirstOrDefault(i => i.PropertyName.Trim().ToUpper() == propName.Trim().ToUpper()); string columnData = GetCsvColumnDataFromPropertyInfo(propInfo); csvStringBuilder.Append(firstColumn ? columnData : "," + columnData); firstColumn = false; } return(csvStringBuilder.ToString() + Environment.NewLine); }