예제 #1
0
        public static T DeSerialize <T>(IJsonSerializer jsonSerializer, byte[] configContent, out string error) where T : class
        {
            error = "";
            define.ConfigTable config = null;

            try
            {
                config = jsonSerializer.DeSerialize <ConfigTable>(configContent);
            }
            catch (Exception e)
            {
                error = "error on parser config content " + e.Message;
                Logger.Instance.LogError(error);
                return(null);
            }

            Type configType = ReflectionManager.Instance.GetTypeByName(config.ConfigName);

            //Type configTyep = Type.GetType(config.PackageName + "." + config.ConfigName);

            if (null == configType)
            {
                error = "error on get type by name " + config.PackageName;
                Logger.Instance.LogError(error);
                return(null);
            }
            var configInstance = Activator.CreateInstance(configType);
            var pps            = configType.GetFields(/*BindingFlags.Public | BindingFlags.Instance*/);

            if (pps.Length != 1)
            {
                error = "error field count " + config.PackageName;
                Logger.Instance.LogError(error);
                return(null);
            }
            if (config.Type == ConfigType.TypeList)
            {
                ParserList(configInstance, config, pps[0], out error);
            }
            else
            {
                ParserMap(configInstance, config, pps[0], out error);
            }
            if (error != "")
            {
                Logger.Instance.LogError(error);
            }
            return(configInstance as T);
        }