diff --git a/NTypewriter.Online/NTypewriter.Online.csproj.user b/NTypewriter.Online/NTypewriter.Online.csproj.user
new file mode 100644
index 0000000..94e6971
--- /dev/null
+++ b/NTypewriter.Online/NTypewriter.Online.csproj.user
@@ -0,0 +1,9 @@
+
+
+
+ ProjectDebugger
+
+
+ http
+
+
\ No newline at end of file
diff --git a/NTypewriter.Online/Runner.cs b/NTypewriter.Online/Runner.cs
index 28aac46..2f311d5 100644
--- a/NTypewriter.Online/Runner.cs
+++ b/NTypewriter.Online/Runner.cs
@@ -9,7 +9,9 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using NTypewriter.Online.Adapters;
+using NTypewriter.Ports;
using NTypewriter.Runtime;
+using NTypewriter.Runtime.Scripting;
namespace NTypewriter.Online
{
@@ -58,7 +60,7 @@ public async Task RunAsync(string inputCode, string template, Cancellati
try
{
- var cmd = new RenderTemplatesCommand(null, userCodeProvider, generatedFileReaderWriter, userIO, null, null, null, null);
+ var cmd = new RenderTemplatesCommand(null, userCodeProvider, generatedFileReaderWriter, userIO, null, null, null, null, new ExpressionCompiler(References));
await cmd.Execute(generatorCompilation, new[] { templateToRender });
}
catch (Exception ex)
diff --git a/NTypewriter.Runtime/RenderTemplatesCommand.cs b/NTypewriter.Runtime/RenderTemplatesCommand.cs
index 52e3f29..3ad0010 100644
--- a/NTypewriter.Runtime/RenderTemplatesCommand.cs
+++ b/NTypewriter.Runtime/RenderTemplatesCommand.cs
@@ -4,10 +4,12 @@
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using NTypewriter.Editor.Config;
+using NTypewriter.Ports;
using NTypewriter.Runtime.CodeModel;
using NTypewriter.Runtime.CodeModel.Internals;
using NTypewriter.Runtime.Internals;
using NTypewriter.Runtime.Rendering;
+using NTypewriter.Runtime.Scripting;
using NTypewriter.Runtime.UserCode;
namespace NTypewriter.Runtime
@@ -36,7 +38,8 @@ public class RenderTemplatesCommand
private readonly IUserCodeProvider userCodeProvider;
private readonly IUserInterfaceErrorListUpdater uiErrorList;
private readonly IUserInterfaceOutputWriter uiOutput;
- private readonly IUserInterfaceStatusUpdater uiStatus;
+ private readonly IUserInterfaceStatusUpdater uiStatus;
+ private readonly IExpressionCompiler expressionCompiler;
public RenderTemplatesCommand(ITemplateContentLoader templateContentLoader,
@@ -46,7 +49,9 @@ public RenderTemplatesCommand(ITemplateContentLoader templateContentLoader,
ISolutionItemsManager solutionItemsManager = null,
ISourceControl sourceControl = null,
IUserInterfaceErrorListUpdater uiErrorList = null,
- IUserInterfaceStatusUpdater uiStatus = null)
+ IUserInterfaceStatusUpdater uiStatus = null,
+ IExpressionCompiler expressionCompiler = null
+ )
{
this.templateContentLoader = templateContentLoader;
this.userCodeProvider = userCodeProvider;
@@ -56,6 +61,7 @@ public RenderTemplatesCommand(ITemplateContentLoader templateContentLoader,
this.solutionItemsManager = solutionItemsManager;
this.sourceControl = sourceControl ?? NullObject.Singleton;
this.uiStatus = uiStatus ?? NullObject.Singleton;
+ this.expressionCompiler = expressionCompiler ?? ExpressionCompiler.Default;
}
@@ -93,7 +99,7 @@ private async Task Execute(SolutionOrCompilation roslynInput, IList> RenderAsync(string templateFileP
dataModels[VariableNames.Config] = configAdapter;
dataModels[VariableNames.Env] = environmentVariables ?? new EnvironmentVariables();
- var result = await NTypeWriter.Render(template, dataModels, configuration, new ExternalOutputAdapter(output), new ExpressionCompiler());
+ var result = await NTypeWriter.Render(template, dataModels, configuration, new ExternalOutputAdapter(output), expressionCompiler);
output.Info("Used configuration : " + editorConfig.ToString());
diff --git a/NTypewriter.Runtime/Scripting/ExpressionCompiler.cs b/NTypewriter.Runtime/Scripting/ExpressionCompiler.cs
index f83f8ee..4210d7b 100644
--- a/NTypewriter.Runtime/Scripting/ExpressionCompiler.cs
+++ b/NTypewriter.Runtime/Scripting/ExpressionCompiler.cs
@@ -11,8 +11,9 @@
namespace NTypewriter.Runtime.Scripting
{
- internal class ExpressionCompiler : IExpressionCompiler
+ public class ExpressionCompiler : IExpressionCompiler
{
+ private static readonly Lazy defaultSingleton = new Lazy(() => new ExpressionCompiler());
private static readonly Type[] RefTypeMarkers =
[
typeof(NTypewriter.CodeModel.ICodeModel),
@@ -24,10 +25,12 @@ internal class ExpressionCompiler : IExpressionCompiler
"System",
"NTypewriter.CodeModel",
];
- private static readonly IEnumerable MetadataReferences;
+ private readonly IEnumerable MetadataReferences;
+ public static ExpressionCompiler Default => defaultSingleton.Value;
- static ExpressionCompiler()
+
+ public ExpressionCompiler()
{
var additionalReferences = RefTypeMarkers.Select(x => MetadataReference.CreateFromFile(x.Assembly.Location)).ToList();
@@ -37,6 +40,10 @@ static ExpressionCompiler()
MetadataReferences = references;
}
+ public ExpressionCompiler(IEnumerable references)
+ {
+ MetadataReferences = references;
+ }
public Func