示例#1
0
 private void SetBaseTypeFromHost(Athena.Unitop.Sure.Lib.RazorEngine.Compilation.RazorEngineHost mvcHost)
 {
     if (!mvcHost.DefaultBaseTemplateType.IsGenericType)
     {
         SetBaseType(mvcHost.DefaultBaseTemplateType.FullName);
     }
     else
     {
         var modelTypeName = CompilerServicesUtility.ResolveCSharpTypeName(mvcHost.DefaultModelType);
         SetBaseType(mvcHost.DefaultBaseClass + "<" + modelTypeName + ">");
     }
 }
        /// <summary>
        /// Creates a <see cref="RazorEngineHost"/> used for class generation.
        /// </summary>
        /// <param name="templateType">The template base type.</param>
        /// <param name="modelType">The model type.</param>
        /// <param name="className">The class name.</param>
        /// <returns>An instance of <see cref="RazorEngineHost"/>.</returns>
        private Athena.Unitop.Sure.Lib.RazorEngine.Compilation.RazorEngineHost CreateHost(Type templateType, Type modelType, string className)
        {
            var host = new Athena.Unitop.Sure.Lib.RazorEngine.Compilation.RazorEngineHost(CodeLanguage, MarkupParserFactory)
            {
                DefaultBaseTemplateType = templateType,
                DefaultModelType        = modelType,
                DefaultBaseClass        = BuildTypeName(templateType),
                DefaultClassName        = className,
                DefaultNamespace        = "CompiledRazorTemplates.Dynamic",
                GeneratedClassContext   = new GeneratedClassContext("Execute", "Write", "WriteLiteral",
                                                                    "WriteTo", "WriteLiteralTo",
                                                                    "Athena.Unitop.Sure.Lib.RazorEngine.Templating.TemplateWriter",
                                                                    "DefineSection")
                {
                    ResolveUrlMethodName = "ResolveUrl"
                }
            };

            return(host);
        }