Exemplo n.º 1
0
 /// <summary>
 /// Read the specified content.
 /// </summary>
 /// <param name="content">Content.</param>
 public virtual void Read(string content)
 {
     this.s_lstData.Clear();
     string[,] vecStr = SplitCsvGrid(content);
     for (int j = 2; j < vecStr.GetLength(1) - 1; j++)
     {
         Type        tableType = GetType();
         CTable      tb        = ScriptableObject.CreateInstance(tableType) as CTable;
         FieldInfo[] fis       = tableType.GetFields(BindingFlags.Public | BindingFlags.Instance);
         for (int i = 0; i < vecStr.GetLength(0) - 1; i++)
         {
             FieldInfo f = fis[i];
             Type      t = f.FieldType;
             if (t.IsPrimitive)
             {
                 if (t.Equals(typeof(int)))
                 {
                     f.SetValue(tb, int.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(uint)))
                 {
                     f.SetValue(tb, uint.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(float)))
                 {
                     f.SetValue(tb, float.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(double)))
                 {
                     f.SetValue(tb, double.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(long)))
                 {
                     f.SetValue(tb, long.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(ulong)))
                 {
                     f.SetValue(tb, ulong.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(bool)))
                 {
                     f.SetValue(tb, bool.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(byte)))
                 {
                     f.SetValue(tb, byte.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(sbyte)))
                 {
                     f.SetValue(tb, sbyte.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(short)))
                 {
                     f.SetValue(tb, short.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(ushort)))
                 {
                     f.SetValue(tb, ushort.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(char)))
                 {
                     f.SetValue(tb, char.Parse(vecStr[i, j]));
                 }
                 else if (t.Equals(typeof(string)))
                 {
                     f.SetValue(tb, vecStr[i, j]);
                 }
                 else
                 {
                     Debug.LogError(t.Name);
                 }
             }
             else if (t.Equals(typeof(string)))
             {
                 f.SetValue(tb, vecStr[i, j]);
             }
         }
         tb.Add(tb);
     }
 }