コード例 #1
0
        public void ConvertToString_QuotingIsTrueForStrings_ResultAsExpected(Object value, Boolean expected)
        {
            CultureInfo culture = CultureInfo.CurrentUICulture;
            CsvMappings mapping = new CsvMappings();

            ProcessHelper.ConvertToString(value, culture, mapping, out Boolean actual);

            Assert.That(actual, Is.EqualTo(expected));
        }
コード例 #2
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());
        }