Example #1
0
        public static void Static(ITextTemplatingEngineHost host, string qualifiedAssemblyName, GrassOptions codeGenOptions = null)
        {
            var options = codeGenOptions ?? new GrassOptions();

            var callContext = CallContext.LogicalGetData("NamespaceHint");
            var ns          = callContext == null ? "ArtisanCode.Grass.GeneratedContent" : callContext.ToString();

            var staticClass = new ClassDefinition(qualifiedAssemblyName, ns, options);

            staticClass.PopulateStaticMethods(codeGenOptions);

            ICodeGen engine = CreateCodeGenEngine(host);

            var emittedInterface     = engine.EmitInterface(ns, staticClass, options);
            var emittedStaticWrapper = engine.EmitStaticWrapperClass(ns, staticClass, options);

            string templateDirectory    = Path.GetDirectoryName(host.TemplateFile);
            string interfaceFilePath    = Path.Combine(templateDirectory, emittedInterface.Filename);
            string classWrapperFilePath = Path.Combine(templateDirectory, emittedStaticWrapper.Filename);


            WriteCodefileToDisk(engine, emittedInterface.CompilationOutput, interfaceFilePath);
            WriteCodefileToDisk(engine, emittedStaticWrapper.CompilationOutput, classWrapperFilePath);

            AddFileToTemplate(host, interfaceFilePath);
            AddFileToTemplate(host, classWrapperFilePath);
        }