Ejemplo n.º 1
0
        public static T4CSharpCodeGenerationResult GenerateCodeBehind([NotNull] IT4File file)
        {
            var solution = file.GetSolution();
            var rootTemplateKindProvider = solution.GetComponent <IT4TemplateKindProvider>();
            var graph = solution.GetComponent <IT4FileDependencyGraph>();
            var root  = graph.FindBestRoot(file.PhysicalPsiSourceFile.NotNull());
            T4CSharpCodeBehindGenerationInfoCollector collector;
            T4CSharpCodeBehindIntermediateConverter   converter;
            var rootTemplateKind = rootTemplateKindProvider.GetTemplateKind(root);

            if (rootTemplateKind == T4TemplateKind.Preprocessed)
            {
                bool isRoot = root == file.PhysicalPsiSourceFile;
                collector = new T4PreprocessedCSharpCodeBehindGenerationInfoCollector(solution, root, graph, isRoot);
                var templateDataProvider = new T4PreprocessedClassNameProvider(root);
                converter = new T4CSharpCodeBehindIntermediateConverter(file, templateDataProvider, isRoot);
            }
            else
            {
                converter = new T4CSharpExecutableCodeBehindIntermediateConverter(file);
                collector = new T4CSharpCodeBehindGenerationInfoCollector(solution);
            }

            return(converter.Convert(collector.Collect(file)));
        }
Ejemplo n.º 2
0
        public static T4CSharpCodeGenerationResult GeneratePreprocessedCode([NotNull] IT4File file)
        {
            var solution  = file.GetSolution();
            var collector = new T4CSharpPreprocessedCodeGenerationInfoCollector(solution);

            file.AssertContainsNoIncludeContext();
            var nameProvider = new T4PreprocessedClassNameProvider(file.PhysicalPsiSourceFile.NotNull());
            var converter    = new T4CSharpRealIntermediateConverter(file, nameProvider);

            return(converter.Convert(collector.Collect(file)));
        }