示例#1
0
        /// <summary>
        /// This method tries to write a particular line into given stream according
        /// to given parameter set.
        /// </summary>
        /// <remarks>
        /// This method may throw exceptions which must be handled by the caller.
        /// </remarks>
        /// <param name="writer">
        /// The stream writer to be used to push data.
        /// </param>
        /// <param name="separator">
        /// The delimiter to be used to separate each column.
        /// </param>
        /// <param name="textual">
        /// The flag indicating how strings have to be handled. If true then all string
        /// are enclosed in double-quotes. If false then only the necessary strings are
        /// enclosed in double-quotes.
        /// </param>
        /// <param name="culture">
        /// The culture to be used for data conversion.
        /// </param>
        /// <param name="mapping">
        /// The mapping to be used for value transformation.
        /// </param>
        /// <param name="values">
        /// A list of values representing a single line of the CSV file.
        /// </param>
        private static void WriteLine(StreamWriter writer, Char separator, Boolean textual, CultureInfo culture, CsvMappings mapping, IEnumerable <Object> values)
        {
            StringBuilder builder = new StringBuilder(1024);

            if (values != null && values.Any())
            {
                foreach (Object value in values)
                {
                    String current = ProcessHelper.ConvertToString(value, culture, mapping);
                    builder.Append(ProcessHelper.ConvertToOutput(current, separator, textual));
                }
            }

            writer.WriteLine(ProcessHelper.FixupOutput(builder, separator).ToString());
        }
        /// <summary>
        /// This method tries to write the header information into given stream
        /// according to given parameter set.
        /// </summary>
        /// <remarks>
        /// <para>
        /// The method writes either the predefined CSV column header or the name
        /// of the original property.
        /// </para>
        /// <para>
        /// This method may throw exceptions which must be handled by the caller.
        /// </para>
        /// </remarks>
        /// <param name="writer">
        /// The stream writer to be used to push data.
        /// </param>
        /// <param name="separator">
        /// The delimiter to be used to separate each column.
        /// </param>
        /// <param name="textual">
        /// The flag indicating how strings have to be handled. If true then all
        /// string are enclosed in double-quotes. If false then only the necessary
        /// strings are enclosed in double-quotes.
        /// </param>
        /// <param name="settings">
        /// A list of settings that describe the expected structure of the CSV
        /// file.
        /// </param>
        private static void WriteHead(StreamWriter writer, Char separator, Boolean textual, IEnumerable <ItemDescriptor> settings)
        {
            StringBuilder builder = new StringBuilder(1024);

            foreach (ItemDescriptor setting in settings)
            {
                if (setting.Column.IsHeader)
                {
                    builder.Append(ProcessHelper.ConvertToOutput(setting.Column.Header, separator, textual));
                }
                else
                {
                    builder.Append(ProcessHelper.ConvertToOutput(setting.Origin.Name, separator, textual));
                }
            }

            writer.WriteLine(ProcessHelper.FixupOutput(builder, separator).ToString());
        }
示例#3
0
 public void ConvertToOutput_ValueAutoQuoting_ResultAsExpected(String value, Char separator, Boolean quoting, String expected)
 {
     Assert.That(ProcessHelper.ConvertToOutput(value, separator, quoting), Is.EqualTo(expected));
 }