예제 #1
0
        public async Task <string> ProcessRazorTemplate(string content)
        {
            var className      = "GeneratedClass";
            var classNamespace = "Generated";
            var assemblyName   = "Generated";

            var preprocessResult = PreprocessRazorTemplate(content, className, classNamespace);

            var compiler = new RoslynCompilationService(_libraryExporter, _host);
            var assembly = compiler.Compile(assemblyName, preprocessResult);

            var instanceType = assembly.GetType(classNamespace + "." + className);
            var instance     = (TemplateBase)Activator.CreateInstance(instanceType);

            return(await instance.GenerateCodeAsync());
        }
예제 #2
0
        public string ProcessT4Template(string content)
        {
            var className      = "GeneratedClass";
            var classNamespace = "Generated";
            var assemblyName   = "Generated";

            var preResult = PreprocessT4Template(content, className, classNamespace);

            var compiler = new RoslynCompilationService(_libraryExporter, _host);
            var transformationAssembly = compiler.Compile(assemblyName, preResult);

            var transformationType = transformationAssembly.GetType(classNamespace + "." + className);
            var transformation     = (TextTransformationBase)Activator.CreateInstance(transformationType);

            transformation.Host = _host;
            return(transformation.TransformText());
        }