Esempio n. 1
0
        /// <summary>
        /// Imports data from a csv file
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="separator"></param>
        public void FromCsvStream(Stream stream, char separator = ',')
        {
            using var sr = new StreamReader(stream);

            // first line is the header
            Headers.Clear();
            var headerline = sr.ReadLine();

            if (string.IsNullOrEmpty(headerline))
            {
                return;
            }

            var array = headerline.Split(separator);

            for (var i = 0; i < array.Length; i++)
            {
                var item    = array[i];
                var cstring = new CString(cr2w, Headers, i.ToString());
                cstring.SetValue(item);
                Headers.Add(cstring);
            }
            Headers.IsSerialized = true;

            // read elements
            string line;
            var    cnt = 0;

            while ((line = sr.ReadLine()) != null)
            {
                // check if same columns as header
                var columns = line.Split(separator);
                if (columns.Length != Headers.Count)
                {
                    throw new SerializationException();
                }

                var row = new CArray <CString>(cr2w, Data, cnt.ToString());
                for (var i = 0; i < columns.Length; i++)
                {
                    var item    = columns[i];
                    var cstring = new CString(cr2w, null, i.ToString());
                    cstring.SetValue(item);
                    row.Add(cstring);
                }

                Data.Add(row);
                cnt++;
            }
            Data.IsSerialized = true;
        }
 public gameDeviceResourceData(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name)
 {
     CookedDeviceData = CR2WTypeManager.Create("array:gameCookedDeviceDataCompressed",
                                               nameof(CookedDeviceData), cr2w, this) as CArray <gameCookedDeviceDataCompressed>;
 }