Esempio n. 1
0
        /// <summary>
        /// Renders the value of the column.
        /// </summary>
        /// <param name="defintion"> The CSV definition. </param>
        /// <param name="value"> The value to render. </param>
        /// <param name="culture"> the culture to render in. </param>
        /// <param name="formatter"> The formatter to use for rendering the value into the cell. </param>
        /// <returns>A string that can be directly written into the CSV file. </returns>
        protected override string OnRender(ICsvDefinition defintion, IEnumerable <TArray> value, CultureInfo culture, IStringFormatter formatter)
        {
            var values = value.Select(e => CleanAndFormatValue(defintion, e)).ToArray();

            var element = string.Join(this.ElementDelimiter, values);

            return(formatter.FormatStringCell(element, defintion.RemoveNewLineCharacters));
        }
Esempio n. 2
0
        protected virtual string OnRender(ICsvDefinition defintion, TResult value, CultureInfo formattingCulture, IStringFormatter formatter)
        {
            if (value == null)
            {
                return(string.Empty);
            }

            return(value.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Executed each time the cell/value is written to a file.
        /// </summary>
        /// <param name="defintion"> The CSV definition. </param>
        /// <param name="value"> The value to render. </param>
        /// <param name="culture"> the culture to render in. </param>
        /// <param name="formatter"> The formatter to use for rendering the value into the cell. </param>
        /// <returns>A string that can be directly written into the CSV file. </returns>
        public override string[] Render(ICsvDefinition defintion, TSource value, CultureInfo culture, IStringFormatter formatter)
        {
            var collection = this.Selector(value);

            return((from item in collection
                    let column = converter(item)
                                 select column.Render(defintion, item, culture, formatter))
                   .SelectMany(elements => elements)
                   .ToArray());
        }
Esempio n. 4
0
        protected override string OnRender(ICsvDefinition defintion, string value, CultureInfo culture, IStringFormatter formatter)
        {
            var text = this.Format(value ?? string.Empty, culture);

            if (this.ForceNumberToTextFormatting)
            {
                return(formatter.FormatForcedExcelStringCell(text, defintion.RemoveNewLineCharacters));
            }

            return(formatter.FormatStringCell(text, defintion.RemoveNewLineCharacters));
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsvStreamLineReader"/> class.
 /// </summary>
 /// <param name="definition">The CSV definition.</param>
 /// <param name="headers">The header names.</param>
 public CsvStreamLineReader(ICsvDefinition definition, HeaderCollection headers)
 {
     this.headers    = headers;
     this.definition = definition;
 }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsvStreamLineReader"/> class.
 /// </summary>
 /// <param name="definition">The CSV definition.</param>
 /// <param name="headers">The header names.</param>
 public CsvStreamLineReader(ICsvDefinition definition, params string[] headers)
     : this(definition, new HeaderCollection(headers))
 {
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsvStreamLineReader"/> class.
 /// </summary>
 public CsvStreamLineReader(ICsvDefinition definition)
     : this(definition, new string[] { })
 {
 }
Esempio n. 8
0
 /// <summary>Executed each time the cell/value is written to a file.</summary>
 /// <param name="defintion">The CSV definition.</param>
 /// <param name="value">The value to render.</param>
 /// <param name="culture">the culture to render in.</param>
 /// <param name="formatter">The formatter to use for rendering the value into the cell.</param>
 /// <returns>A string that can be directly written into the CSV file.</returns>
 protected override string OnRender(ICsvDefinition defintion, int?value, CultureInfo culture, IStringFormatter formatter)
 {
     return(this.Format(value, culture));
 }
Esempio n. 9
0
        /// <summary>
        /// Renders the specified element contents.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public virtual string[] Render(ICsvDefinition definition, TSource element, CultureInfo formattingCulture, IStringFormatter formatter)
        {
            var value = this.Selector(element);

            return(new[] { this.OnRender(definition, value, formattingCulture.Parent, formatter) });
        }
Esempio n. 10
0
        /// <summary>
        /// Renders the specified element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns></returns>
        public override string[] Render(ICsvDefinition defintion, TSource element, CultureInfo culture, IStringFormatter formatter)
        {
            var collection = this.Selector(element);

            return(this.ProcessElementsByHeaderNames(collection, culture, formatter).ToArray());
        }
Esempio n. 11
0
 private string CleanAndFormatValue(ICsvDefinition defintion, TArray e)
 {
     return(this.Format(e).Replace(this.ElementDelimiter, "_"));
 }