public static IEnumerable <IRule <ICsvLine> > Create(IOutputConfig outPutConfig) { var aResult = new List <CsvLineRule>(); aResult.Add(new CsvLineRule(x => { var i = 0; foreach (var val in getValues(x, null)) { i++; var oEx = new ConditionException($"Posición({i}): el registro '{val}' no puede contener el delimitador de destino {outPutConfig.delimiter}"); if (val.Contains(outPutConfig.delimiter)) { throw oEx; } } return(true); })); aResult.AddRange(Create(outPutConfig.conditions)); return(aResult); }
private static string[] DataToString(IEnumerable <string> keys, IEnumerable <ICsvLine> lines, IEnumerable <ErrorLine> errors, IOutputConfig config) { errors = errors ?? new List <ErrorLine>(); var delimiter = config.delimiter.ToString(); var oResult = new List <string>() { string.Join(delimiter, keys) }; var errorLines = errors .Where(x => x.Index != null) .Select(x => x.Index) .Distinct() .ToList(); var i = 0; foreach (var line in lines) { var linetoAdd = new string[keys.Count()]; if (!errorLines.Contains(i++)) { var j = 0; foreach (var key in keys) { linetoAdd[j++] = line[key]; } oResult.Add(string.Join(delimiter, linetoAdd)); } } return(oResult.ToArray()); }