public FileSystemRepository( ITemplatePathResolver pathResolver, IFileSystem fileSystem, ITemplateCompiler compiler, ITemplateClassNameBuilder classNameBuilder, ITemplateCodeBuilder codeBuilder, ICodeDomProviderFactory codeDomProviderFactory, ICompiledTemplateFactory compiledTemplateFactory, IFileSystemRepositoryConfiguration configuration) { pathResolver.ThrowIfNull("pathResolver"); fileSystem.ThrowIfNull("fileSystem"); compiler.ThrowIfNull("compiler"); classNameBuilder.ThrowIfNull("classNameBuilder"); codeBuilder.ThrowIfNull("codeBuilder"); codeDomProviderFactory.ThrowIfNull("codeDomProviderFactory"); compiledTemplateFactory.ThrowIfNull("compiledTemplateFactory"); configuration.ThrowIfNull("configuration"); _pathResolver = pathResolver; _fileSystem = fileSystem; _compiler = compiler; _classNameBuilder = classNameBuilder; _codeBuilder = codeBuilder; _codeDomProviderFactory = codeDomProviderFactory; _compiledTemplateFactory = compiledTemplateFactory; _configuration = configuration; }
public Type Compile <TTemplate>( string templateContents, string className, ITemplateCodeBuilder templateCodeBuilder, CodeDomProvider codeDomProvider, Action <CodeTypeDeclaration> typeConfigurationDelegate, IEnumerable <string> namespaceImports) where TTemplate : ITemplate { templateContents.ThrowIfNull("templateContents"); className.ThrowIfNull("className"); templateCodeBuilder.ThrowIfNull("templateCodeBuilder"); codeDomProvider.ThrowIfNull("codeDomProvider"); namespaceImports.ThrowIfNull("namespaceImports"); BuildCodeResult buildCodeResult = templateCodeBuilder.BuildCode <TTemplate>(templateContents, className, typeConfigurationDelegate, namespaceImports); var parameters = new CompilerParameters { GenerateInMemory = true, GenerateExecutable = false, IncludeDebugInformation = false, CompilerOptions = "/target:library /optimize" }; string[] assemblyLocations = _referenceResolver.ResolveAssemblyLocations().ToArray(); parameters.ReferencedAssemblies.AddRange(assemblyLocations); CompilerResults compilerResults = codeDomProvider.CompileAssemblyFromDom(parameters, buildCodeResult.CompileUnit); if (compilerResults.Errors != null && compilerResults.Errors.Count > 0) { throw new TemplateCompilationException(compilerResults.Errors); } return(compilerResults.CompiledAssembly.GetType(buildCodeResult.TypeFullName)); }