From e7d538005dbff9e6e69809308beef7876cf8812f Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 15 Nov 2017 12:13:18 +0100 Subject: [PATCH] Added support for custom templates with the msbuild integration --- .../Tasks/EventSourceGeneratorTaskBase.cs | 18 +++++++++++++++--- .../Tasks/GeneratorConsoleConfiguration.cs | 10 ++++++++-- src/Thor.Generator.targets | 5 +++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/Generator/Tasks/EventSourceGeneratorTaskBase.cs b/src/Generator/Tasks/EventSourceGeneratorTaskBase.cs index aa07d17..70db967 100644 --- a/src/Generator/Tasks/EventSourceGeneratorTaskBase.cs +++ b/src/Generator/Tasks/EventSourceGeneratorTaskBase.cs @@ -61,6 +61,12 @@ protected EventSourceGeneratorTaskBase(IConsole console, TemplateStorage templat /// The name of the template. public string TemplateName { get; set; } + /// + /// Gets or sets a custom template file + /// that shall be used to generate event sources. + /// + public string TemplateFile { get; set; } + /// /// Analyzes the given and /// generates the event source into the same project. @@ -124,11 +130,17 @@ protected void GenerateEventSources(Project source, Project target) /// protected Template GetTemplate() { - if (string.IsNullOrEmpty(TemplateName)) + if(!string.IsNullOrEmpty(TemplateFile)) { - return _templateStorage.GetTemplate(Language); + return Template.FromFile(TemplateFile); } - return _templateStorage.GetCustomTemplate(TemplateName); + + if (!string.IsNullOrEmpty(TemplateName)) + { + return _templateStorage.GetCustomTemplate(TemplateName); + } + + return _templateStorage.GetTemplate(Language); } } } diff --git a/src/Generator/Tasks/GeneratorConsoleConfiguration.cs b/src/Generator/Tasks/GeneratorConsoleConfiguration.cs index 65122a4..4575fcd 100644 --- a/src/Generator/Tasks/GeneratorConsoleConfiguration.cs +++ b/src/Generator/Tasks/GeneratorConsoleConfiguration.cs @@ -24,7 +24,10 @@ public GeneratorConsoleConfiguration() .WithName("recursive", 'r') .And() .Argument(t => t.TemplateName) - .WithName("template"); + .WithName("template") + .And() + .Argument(t => t.TemplateFile) + .WithName("template-file"); Bind() .AsDefault() @@ -39,7 +42,10 @@ public GeneratorConsoleConfiguration() .Position(1) .And() .Argument(t => t.TemplateName) - .WithName("template"); + .WithName("template") + .And() + .Argument(t => t.TemplateFile) + .WithName("template-file"); Bind() .WithName("templates", "export") diff --git a/src/Thor.Generator.targets b/src/Thor.Generator.targets index 088286a..37e22cc 100644 --- a/src/Thor.Generator.targets +++ b/src/Thor.Generator.targets @@ -13,7 +13,8 @@ - - + + + \ No newline at end of file