public override CVariable SetValue(object val)
        {
            this.Value = val switch
            {
                string s => s,
                CString cvar => cvar.Value,
                       _ => this.Value
            };

            return(this);
        }
Example #2
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;
        }
Example #3
0
 public LocalizationString(IRed4EngineFile cr2w, CVariable parent, string name) : base(cr2w, parent, name)
 {
     Unk1  = new CUInt64(cr2w, this, nameof(Unk1));
     Value = new CString(cr2w, this, nameof(Value));
 }
Example #4
0
 public NodeRef(CR2WFile cr2w, CVariable parent, string name) : base(cr2w, parent, name)
 {
     Value = new CString(cr2w, this, nameof(Value));
 }