internal static void Transform(TextTransformerBase transformer) { //Prepare the argument that will be passes to the template var class1 = new ClassDefinition { Name = "TestClass", Namespace = "TC.CustomTemplating.Example.Generated" }; class1.Properties.Add(new Property("Name", typeof(string))); class1.Properties.Add(new Property("Lenght", typeof(int))); class1.Properties.Add(new Property("L", typeof(int))); //Get template from the embedded resources string template = TemplateResources.Get("TC.CustomTemplating.Example.Class.tt", typeof(ClassTemplate)); //Allows us to show the compiled class transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated; //start the tranformation var output = transformer.Transform(template, "Class", class1); Console.WriteLine("--BEGIN OUTPUT--"); Console.WriteLine(output); Console.WriteLine("--END OUTPUT--"); transformer.ClassDefinitionGenerated -= Host_ClassDefinitionGenerated; }
/// <summary> /// Initializes a new instance of the <see cref="Controller"/> class. /// </summary> public Controller() { TemplateDomainAction = TemplateDomainActionCreate; Template = DefaultTemplate; Arguments = new TemplateArgumentCollection { new TemplateArgument("Argument", "Test") }; transformer = new TextTransformer(); transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated; RefreshDomainProperties(); }
/// <summary> /// Toggles the template domain. /// </summary> internal void ToggleTemplateDomain() { transformer.ClassDefinitionGenerated -= Host_ClassDefinitionGenerated; if (domain == null) { domain = new DomainTextTransformer(); domain.AutoRecycle = true; domain.RecycleThreshold = 5; TemplateDomainAction = TemplateDomainActionUnload; transformer = domain; } else { domain.Dispose(); domain = null; TemplateDomainAction = TemplateDomainActionCreate; transformer = new TextTransformer(); } transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated; RefreshDomainProperties(); }