protected void ReadFile(IFileContainer file)
        {
            var raw_lines = file.ReadAllLines();

            _lines = new List <item_type>();

            if (_titles == null)
            {
                _titles = new string[0]; // If set in constructor. Don't overwrite it here.
            }
            foreach (var raw_line in raw_lines)
            {
                string             comment;
                TeaboxDataLineType type;
                string[]           data;

                var atts = typeof(item_type).GetCustomAttributes(typeof(TeaboxDataNoComments), true); // ToDo Test

                ParseLine(raw_line, (atts.Length == 1 && atts[0].GetType() == typeof(TeaboxDataNoComments)), out comment, out type, out data);

                if (type == TeaboxDataLineType.Titles && _titles.Length == 0)
                {
                    _titles = new string[data.Length];
                    Array.Copy(data, _titles, data.Length);
                }

                var new_item = new item_type();
                TeaboxDataLine.SetData(new_item, data);
                TeaboxDataLine.SetTitles(new_item, _titles);
                TeaboxDataLine.SetLineType(new_item, ref type);
                TeaboxDataLine.SetComment(new_item, ref comment);
                TeaboxDataLine.SetPropertiesFromData <item_type>(new_item);
                _lines.Add(new_item);
            }
        }
Esempio n. 2
0
        // ToDo Write tests for this
        public static void SetDataFromProperties <line_type>(TeaboxDataLine line) where line_type : TeaboxDataLine
        {
            foreach (var prop in typeof(line_type).GetProperties())
            {
                var atts = prop.GetCustomAttributes(typeof(TeaboxDataAttribute), true);

                if (atts.Length == 1 && atts[0].GetType() == typeof(TeaboxDataAttribute))
                {
                    var value_object = prop.GetValue(line);

                    var value_string = "";

                    if (value_object != null)
                    {
                        value_string = value_object.ToString();
                    }

                    TeaboxDataLine.SetData(line, prop.Name, value_string);
                }
            }
        }