예제 #1
0
파일: Engine.cs 프로젝트: ks3dev/jntemplate
        /// <summary>
        /// 引擎配置
        /// </summary>
        /// <param name="conf">配置内容</param>
        /// <param name="ctx">默认模板上下文</param>
        public static void Configure(EngineConfig conf, TemplateContext ctx)
        {
            if (conf == null)
            {
                throw new ArgumentNullException("conf");
            }

            if (conf.TagParsers == null)
            {
                conf.TagParsers = conf.TagParsers = Field.RSEOLVER_TYPES;
            }
            _context = ctx;
            ITagParser[] parsers = new ITagParser[conf.TagParsers.Length];

            for (Int32 i = 0; i < conf.TagParsers.Length; i++)
            {
                parsers[i] = (ITagParser)Activator.CreateInstance(Type.GetType(conf.TagParsers[i]));
            }

            ICache cache = null;
            if (!string.IsNullOrEmpty(conf.CachingProvider))
            {
                cache = (ICache)Activator.CreateInstance(Type.GetType(conf.CachingProvider));
            }

            Parser.TagTypeResolver resolver = new Parser.TagTypeResolver(parsers);
            _engineRuntime = new Runtime(resolver,
                cache,
                conf);
        }