예제 #1
0
 public void Cleanup()
 {
     if (!IsNull)
     {
         CsvHelper.Cleanup(m_Values);
     }
 }
예제 #2
0
        public void Deserialize <T>(Stream stream, Dictionary <Int32, T> output)
        {
            List <String[]> list = CsvHelper.Parse(stream);

            CsvHelper.Cleanup(list);
            if (list.Count > 1)
            {
                Int32 i;
                for (i = 0; i < list.Count; i++)
                {
                    if (list[i] != null && !CsvHelper.IsComment(list[i]))
                    {
                        break;
                    }
                }
                Deserialize <T>(list[i], list, i + 1, output);
            }
        }
예제 #3
0
        public Array Deserialize(Stream stream)
        {
            List <String[]> list = CsvHelper.Parse(stream);

            CsvHelper.Cleanup(list);
            if (list.Count > 1)
            {
                Int32 i;
                for (i = 0; i < list.Count; i++)
                {
                    if (list[i] != null && !CsvHelper.IsComment(list[i]))
                    {
                        break;
                    }
                }
                return(Deserialize(list[i], list, i + 1));
            }
            return(null);
        }
예제 #4
0
        private Array Deserialize(String[] columns, List <String[]> values, Int32 valueOffset)
        {
            FieldInfo[] columns2  = FindColumnInfos(columns);
            ArrayList   arrayList = new ArrayList(values.Count - valueOffset);

            for (Int32 i = valueOffset; i < values.Count; i++)
            {
                if (values[i] != null && !CsvHelper.IsComment(values[i]))
                {
                    Object obj = Activator.CreateInstance(mObjectType);
                    SetFieldValues(i + 1, obj, columns2, values[i]);
                    arrayList.Add(obj);
                }
            }
            Array array = Array.CreateInstance(mObjectType, arrayList.Count);

            arrayList.CopyTo(array);
            return(array);
        }
예제 #5
0
        public static CsvFile Merge(CsvFile fileA, CsvFile fileB)
        {
            if (fileA.Columns.Length < fileB.Columns.Length)
            {
                CsvFile csvFile = fileB;
                fileB = fileA;
                fileA = csvFile;
            }
            List <String[]> list  = new List <String[]>(fileA.m_Values);
            List <String[]> list2 = new List <String[]>(fileB.m_Values);

            CsvHelper.Cleanup(list);
            CsvHelper.Cleanup(list2);
            List <String> list3 = new List <String>(fileA.Columns.Length + fileB.Columns.Length);

            list3.AddRange(fileA.Columns);
            list3.AddRange(fileB.Columns);
            CsvFile csvFile2 = new CsvFile();

            csvFile2.IsNull  = false;
            csvFile2.Columns = list3.ToArray();
            list3.Clear();
            for (Int32 i = 0; i < list.Count; i++)
            {
                list3.AddRange(list[i]);
                if (i < list2.Count)
                {
                    list3.AddRange(list2[i]);
                }
                else
                {
                    Int32 num = fileB.Columns.Length;
                    while (num-- >= 0)
                    {
                        list3.Add(String.Empty);
                    }
                }
                csvFile2.m_Values.Add(list3.ToArray());
                list3.Clear();
            }
            return(csvFile2);
        }
예제 #6
0
        private void Deserialize <T>(String[] columns, List <String[]> values, Int32 valueOffset, Dictionary <Int32, T> output)
        {
            FieldInfo[] columns2 = FindColumnInfos(columns);
            for (Int32 i = valueOffset; i < values.Count; i++)
            {
                String[] data = values[i];
                if (data != null && !CsvHelper.IsComment(data))
                {
                    Int32 staticId = Int32.Parse(data[0], CultureInfo.InvariantCulture);

                    if (!output.TryGetValue(staticId, out var obj))
                    {
                        obj = (T)Activator.CreateInstance(mObjectType);
                        output.Add(staticId, obj);
                    }

                    SetFieldValues(i + 1, obj, columns2, data);
                }
            }
        }
예제 #7
0
 public CsvFile(Stream stream)
 {
     try
     {
         if (stream != null)
         {
             m_Values = CsvHelper.Parse(stream);
             CsvHelper.ErrorCheck(m_Values);
             if (m_Values.Count > 0)
             {
                 Columns = m_Values[0];
                 m_Values.RemoveAt(0);
                 IsNull = false;
             }
             else
             {
                 Columns = new String[0];
                 IsNull  = true;
             }
         }
         else
         {
             Columns  = new String[0];
             m_Values = new List <String[]>();
             IsNull   = true;
         }
         Values = m_Values.AsReadOnly();
     }
     finally
     {
         if (stream != null)
         {
             ((IDisposable)stream).Dispose();
         }
     }
 }