Example #1
0
    public object[] Import(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }
        if (!path.EndsWith(".json"))
        {
            path += ".json";
        }

        string txt = FileGameUtil.ReadText(path);

        if (string.IsNullOrEmpty(txt))
        {
            return(null);
        }

        List <object> instanceList = new List <object>();
        ArrayList     dataJson     = MiniJson.jsonDecode(txt) as ArrayList;

        foreach (object obj in dataJson)
        {
            Hashtable itemTab   = obj as Hashtable;
            Type      classType = Type.GetType(Convert.ToString(itemTab["type"]));

            Hashtable dataTab = itemTab["data"] as Hashtable;
            Dictionary <string, object> reflectDic = CopyTo(dataTab);
            object instance = InjectDataBinder.BindingData(classType, reflectDic);
            if (instance != null)
            {
                instanceList.Add(instance);
            }
        }
        return(instanceList.ToArray());
    }