Example #1
0
        public static void WriteObjectRow(TextWriter writer, IEnumerable <object> row)
        {
            var ranOnce = false;

            foreach (var field in row)
            {
                JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);

                writer.Write(field.ToCsvField());
            }
            writer.WriteLine();
        }
Example #2
0
    /// <summary>
    /// Writes the list string.
    /// </summary>
    /// <param name="serializer">The serializer.</param>
    /// <param name="writer">The writer.</param>
    /// <param name="list">The list.</param>
    public static void WriteListString(ITypeSerializer serializer, TextWriter writer, List <string> list)
    {
        writer.Write(JsWriter.ListStartChar);

        var ranOnce = false;

        foreach (var x in list)
        {
            JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);
            serializer.WriteString(writer, x);
        }

        writer.Write(JsWriter.ListEndChar);
    }
Example #3
0
        public static void Write(TextWriter writer, IEnumerable <T> records)
        {
            if (OptimizedWriter != null)
            {
                OptimizedWriter(writer, records);
                return;
            }

            if (!CsvConfig <T> .OmitHeaders && Headers.Count > 0)
            {
                var ranOnce = false;
                foreach (var header in Headers)
                {
                    JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);

                    writer.Write(header);
                }
                writer.WriteLine();
            }

            if (records == null)
            {
                return;
            }

            if (typeof(T).IsValueType || typeof(T) == typeof(string))
            {
                var singleRow = GetSingleRow(records, typeof(T));
                WriteRow(writer, singleRow);
                return;
            }

            var row = new string[Headers.Count];

            foreach (var record in records)
            {
                for (var i = 0; i < PropertyGetters.Count; i++)
                {
                    var propertyGetter = PropertyGetters[i];
                    var value          = propertyGetter(record) ?? "";

                    var strValue = value.GetType() == typeof(string)
                                           ? (string)value
                                           : TypeSerializer.SerializeToString(value);

                    row[i] = strValue;
                }
                WriteRow(writer, row);
            }
        }
Example #4
0
    /// <summary>
    /// Writes the i list string.
    /// </summary>
    /// <param name="serializer">The serializer.</param>
    /// <param name="writer">The writer.</param>
    /// <param name="list">The list.</param>
    public static void WriteIListString(ITypeSerializer serializer, TextWriter writer, IList <string> list)
    {
        writer.Write(JsWriter.ListStartChar);

        var ranOnce    = false;
        var listLength = list.Count;

        for (var i = 0; i < listLength; i++)
        {
            JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);
            serializer.WriteString(writer, list[i]);
        }

        writer.Write(JsWriter.ListEndChar);
    }
Example #5
0
    /// <summary>
    /// Writes the string array.
    /// </summary>
    /// <param name="serializer">The serializer.</param>
    /// <param name="writer">The writer.</param>
    /// <param name="oList">The o list.</param>
    public static void WriteStringArray(ITypeSerializer serializer, TextWriter writer, object oList)
    {
        writer.Write(JsWriter.ListStartChar);

        var list       = (string[])oList;
        var ranOnce    = false;
        var listLength = list.Length;

        for (var i = 0; i < listLength; i++)
        {
            JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);
            serializer.WriteString(writer, list[i]);
        }

        writer.Write(JsWriter.ListEndChar);
    }
Example #6
0
        public static void Write(TextWriter writer, IEnumerable <List <string> > rows)
        {
            if (Headers.Count > 0)
            {
                var ranOnce = false;
                foreach (var header in Headers)
                {
                    JsWriter.WriteItemSeperatorIfRanOnce(writer, ref ranOnce);

                    writer.Write(header);
                }
                writer.WriteLine();
            }

            foreach (var row in rows)
            {
                WriteRow(writer, row);
            }
        }