Exemplo n.º 1
0
        /// <summary>
        /// converts the table obtained by <see cref="FormatTable"/> into csv-text.
        /// </summary>
        /// <param name="s">speeratior in the text</param>
        /// <param name="sepString">string used to speerate columns in the text output</param>
        /// <param name="RowFilter">
        /// select a certain subset of keys, resp. table rows.
        /// </param>
        public void WriteToStream(TextWriter s, string sepString = "\t", IEnumerable <CompositeKey> RowFilter = null)
        {
            string[] KeyColumnNames;
            string[] ValueColumnNames;
            object[,] KeyTable;
            object[,] ValueTable;
            FormatTable(out KeyColumnNames, out ValueColumnNames, out KeyTable, out ValueTable, RowFilter);


            object[,] fullTable =
                ArrayTools.CatVert <object>(
                    ArrayTools.CatHoriz <object>(KeyColumnNames.ToRowVec(), ValueColumnNames.ToRowVec()),
                    ArrayTools.CatHoriz <object>(KeyTable, ValueTable));

            for (int i = 0; i < fullTable.GetLength(0); i++)
            {
                for (int j = 0; j < fullTable.GetLength(1); j++)
                {
                    var o = fullTable[i, j];

                    if (o == null)
                    {
                        s.Write("null");
                    }
                    else if (o is double)
                    {
                        s.Write(((double)o).ToString(NumberFormatInfo.InvariantInfo));
                    }
                    else if (o is float)
                    {
                        s.Write(((float)o).ToString(NumberFormatInfo.InvariantInfo));
                    }
                    else
                    {
                        s.Write(o.ToString());
                    }

                    if (j + 1 < fullTable.GetLength(1))
                    {
                        s.Write(sepString);
                    }
                }
                s.WriteLine();
            }
        }