Esempio n. 1
0
        /// <summary>
        /// 根据模板名称得到模板
        /// </summary>
        /// <param name="TemplateName"></param>
        /// <returns></returns>
        public CodeTemplate GetCodeTemplate(string TemplateName)
        {
            CodeTemplateCompiler compiler = new CodeTemplateCompiler(this.CodeTemplateInfo.DirectoryName + TemplateName);

            CodeTemplate template = null;

            compiler.CodeTemplateInfo.ToString();
            compiler.Compile();
            if (compiler.Errors.Count == 0)
            {
                template = compiler.CreateInstance();
            }
            else
            {
                System.Text.StringBuilder errorMessage = new System.Text.StringBuilder();
                for (int i = 0; i < compiler.Errors.Count; i++)
                {
                    errorMessage.Append(compiler.Errors[i].ToString()).Append("\r\n");
                }
                throw new ApplicationException(errorMessage.ToString());
            }

            //复制属性
            if (template != null)
            {
                CopyPropertiesTo(template);
            }

            return(template);
        }
Esempio n. 2
0
		public CodeTemplate CompileTemplate(string templateName)
		{	
			CodeTemplateCompiler compiler = new CodeTemplateCompiler(templateName);
			compiler.Compile();	
		
			if (compiler.Errors.Count == 0)
			{
				return compiler.CreateInstance();
			}
			else
			{
				return null;
			}
		
		}
Esempio n. 3
0
        public static CodeTemplate CompileTemplate(CodeTemplate parent, string template)
        {
            CodeTemplateCompiler compiler = new CodeTemplateCompiler(template);
            compiler.Compile();

            if (compiler.Errors.Count == 0)
            {
                return compiler.CreateInstance();
            }
            else
            {
                for (int i = 0; i < compiler.Errors.Count; i++)
                {
                    parent.Response.WriteLine(compiler.Errors[i].ToString());
                }
                return null;
            }
        }
Esempio n. 4
0
        public static CodeTemplate CompileTemplate(CodeTemplate parent, string template)
        {
            CodeTemplateCompiler compiler = new CodeTemplateCompiler(template);

            compiler.Compile();

            if (compiler.Errors.Count == 0)
            {
                return(compiler.CreateInstance());
            }
            else
            {
                for (int i = 0; i < compiler.Errors.Count; i++)
                {
                    parent.Response.WriteLine(compiler.Errors[i].ToString());
                }
                return(null);
            }
        }
Esempio n. 5
0
    //获得模版实例
    private CodeTemplate GetCodeTemplate(string TemplateName)
    {
        //CodeTemplate template=null;
        CodeTemplateCompiler compiler = new CodeTemplateCompiler(this.CodeTemplateInfo.DirectoryName + TemplateName);

        compiler.CodeTemplateInfo.ToString();
        compiler.Compile();
        if (compiler.Errors.Count == 0)
        {
            return(compiler.CreateInstance());
        }
        else
        {
            System.Text.StringBuilder errorMessage = new System.Text.StringBuilder();
            for (int i = 0; i < compiler.Errors.Count; i++)
            {
                errorMessage.Append(compiler.Errors[i].ToString()).Append("\n");
            }
            throw new ApplicationException(errorMessage.ToString());
        }
    }
            public static CodeTemplate GetCompiledTemplate(string templatePath)
            {

                CodeTemplateCompiler compiler = new CodeTemplateCompiler(templatePath);
	            compiler.Compile();

                if (compiler.Errors.Count > 0)
                {
                    string errString = "Error Compiling Template\r\n";
                    errString += "- " + templatePath + "\r\n";

                    foreach (System.CodeDom.Compiler.CompilerError err in compiler.Errors)
                    {   
                        errString += err.ErrorText + "\r\n";
                    }
                    throw new ApplicationException(errString);
                }

                return compiler.CreateInstance();

            }
Esempio n. 7
0
        public static CodeTemplate GetCodeTemplate(string TemplateFullName)
        {
            //CodeTemplate template=null;
            CodeTemplateCompiler compiler = new CodeTemplateCompiler(TemplateFullName);
            compiler.CodeTemplateInfo.ToString();
            compiler.Compile();
            if (compiler.Errors.Count == 0)
            {
            return compiler.CreateInstance();
            }
            else
            {
            System.Text.StringBuilder errorMessage = new System.Text.StringBuilder();
            for (int i = 0; i < compiler.Errors.Count; i++)
            {
            errorMessage.Append(compiler.Errors[i].ToString()).Append("\n");
            }
            throw new ApplicationException(errorMessage.ToString());
            }

            return null;
        }