Exemple #1
0
 public abstract void AddElement(RjElement _element);
Exemple #2
0
    public static void Parse(RjElement parent, ExcelWorksheet sheet, ExcelRow row, int index, string key, int maxNum, bool needTakeValue = true)
    {
        if (string.IsNullOrEmpty(key) && (parent.GetClassType() != RjClassType.COLL))
        {
            if (index < maxNum - 1)
            {
                Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum);
            }
            return;
        }
        // filter " and :
        key = key.Replace("\"", "");
        key = key.Replace(":", "");

        for (int i = 0; i < key.Length; ++i)
        {
            if (key[i] == '[')
            {
                //before
                string _key_before = key.Substring(0, i);
                //after
                string _key_after = key.Substring(i + 1, key.Length - i - 1);

                RjColl _coll = new RjColl(_key_before);
                _coll.SetParent(parent);
                parent.AddElement(_coll);
                if (string.IsNullOrEmpty(_key_after))
                {
                    //must add the value
                    AddElement(_coll, sheet, row, index, null);
                    Parse(_coll, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum);
                }
                else
                {
                    Parse(_coll, sheet, row, index, _key_after, maxNum);
                }
                return;
            }
            else if (key[i] == '{')
            {
                string[] _kks  = key.Split('{');
                RjData   _coll = new RjData(_kks[0]);
                _coll.SetParent(parent);
                parent.AddElement(_coll);
                Parse(_coll, sheet, row, index, _kks[1], maxNum);
                return;
            }
            else if (key[i] == ']')
            {
                //string _raw_key=_sheet.Rows[mc_key_row][_index];

                if (needTakeValue)
                {
                    AddElement(parent, sheet, row, index, null);
                }
                parent = parent.GetPerent();
                if (key.Length == 1)
                {
                    if (index < maxNum - 1)
                    {
                        Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum);
                    }
                }
                else
                {
                    string _key_after = key.Substring(i + 1, key.Length - i - 1);
                    Parse(parent, sheet, row, index, _key_after, maxNum);
                }
                return;
            }
            else if (key[i] == '}')
            {
                string _key_before = key.Substring(0, i);
                string _key_after  = key.Substring(i + 1, key.Length - i - 1);
                //				Debug.Log("before:"+_key_before+" after:"+_key_after);
                bool _need_take = true;
                if (!string.IsNullOrEmpty(_key_before))
                {
                    AddElement(parent, sheet, row, index, _key_before);
                    _need_take = false;
                }
                parent = parent.GetPerent();
                if (string.IsNullOrEmpty(_key_after))
                {
                    if (index < maxNum - 1)
                    {
                        Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum);
                    }
                }
                else
                {
                    Parse(parent, sheet, row, index, _key_after, maxNum, _need_take);
                }
                return;
            }
        }

        AddElement(parent, sheet, row, index, key);


        if (index < maxNum - 1)
        {
            Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum);
        }
    }