public override string ToString() { var sb = new StringBuilder(); bool first = true; foreach (var item in _cells) { if (first) { first = false; } else { sb.Append(Seperator); } var a = item; var x = a.ToString(); if (x.Contains(Seperator.ToString())) { x = "\"" + x.Replace("\"", "\"\"") + "\""; } sb.Append(x); } return(sb.ToString()); }
public CSVResult <IEnumerable <T> > ProcessCSV <T>(Stream csvStream) { var result = new CSVResult <IEnumerable <T> > { Output = new List <T>() }; var records = new List <T>(); using (var reader = new StreamReader(csvStream)) { var malformedRow = false; var configuration = new CsvConfiguration(CultureInfo.InvariantCulture) { Delimiter = Seperator.ToString(), BadDataFound = context => { malformedRow = true; result.FailedCount++; Debug.Print(context.RawRecord); } }; using var csv = new CsvReader(reader, configuration); csvStream.Position = 0; CsvHelperMapper.RegisterClassMaps(csv.Context); while (csv.Read()) { try { var record = csv.GetRecord <T>(); if (!malformedRow) { records.Add(record); result.SuccessCount++; } } catch { result.FailedCount++; } result.ProcessedCount++; malformedRow = false; } } result.Output = records; return(result); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { InputList = value as IEnumerable <object>; SetDefaultSeperatorIfNecessary(); if (HasInputList) { return(String.Join(Seperator.ToString() + " ", InputList.Select(o => o.ToString()).ToArray())); } else { return(DefaultReturnValue); } }
public IncludeSelectOptions(ODataQueryOptions options) { var se = options.SelectExpand; if (se != null) { if (se.RawExpand != null) { Includes = se.RawExpand.Split(splitter); } if (se.RawSelect != null) { Selects = se.RawSelect.Split(splitter); } } if (options.Filter != null) { var navs = FindNavigationFilterOptions.GetPaths(options.Filter, Seperator.ToString()); if (navs.Any()) { Includes = (Includes ?? new string[0]).Union(navs).ToArray(); } } if (options.OrderBy != null) { var orderProps = new HashSet <string>(Includes ?? new string[0]); foreach (var n in options.OrderBy.RawValue.Split(splitter)) { int i = n.LastIndexOf(Seperator); if (i > -1) { orderProps.Add(n.Substring(0, i)); } } Includes = orderProps.ToArray(); } }