Skip to content

Commit

Permalink
Restore option to load assembly into the current AppDomain
Browse files Browse the repository at this point in the history
Fixes #169

Happy to refactor and/or add tests as needed.
  • Loading branch information
ajcvickers committed Dec 6, 2023
1 parent d5fb8e6 commit 5f31951
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ partial class CompiledTemplate
class TemplateProcessor : MarshalByRefObject
{
[SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "Needs to be an instance for MarshalByRefObject")]
public string CreateAndProcess (ITextTemplatingEngineHost host, CompiledAssemblyData templateAssemblyData, string templateAssemblyFile, string fullName, CultureInfo culture, string[] referencedAssemblyFiles)
public string CreateAndProcess (ITextTemplatingEngineHost host, CompiledAssemblyData templateAssemblyData, string templateAssemblyFile, string fullName, CultureInfo culture, string[] referencedAssemblyFiles, bool loadAssemblyIntoAppDomain)
{
using var context = new TemplateAssemblyContext (host, referencedAssemblyFiles);

Assembly assembly = templateAssemblyData is not null
? context.LoadInMemoryAssembly (templateAssemblyData)
: context.LoadAssemblyFile (templateAssemblyFile);
Assembly assembly =
templateAssemblyData is not null
? loadAssemblyIntoAppDomain
? Assembly.Load (templateAssemblyData.Assembly)
: context.LoadInMemoryAssembly (templateAssemblyData)
: context.LoadAssemblyFile (templateAssemblyFile);

// MS Templating Engine does not care about the type itself
// it only requires the expected members to be on the compiled type
Expand Down
5 changes: 4 additions & 1 deletion Mono.TextTemplating/Mono.TextTemplating/CompiledTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ TemplateProcessor CreateTemplateProcessor ()
#endif

public string Process ()
=> Process (loadAssemblyIntoAppDomain: false);

public string Process (bool loadAssemblyIntoAppDomain)
{
TemplateProcessor processor = CreateTemplateProcessor ();
return processor.CreateAndProcess (host, templateAssemblyData, templateAssemblyFile, templateClassFullName, culture, ReferencedAssemblyFiles);
return processor.CreateAndProcess (host, templateAssemblyData, templateAssemblyFile, templateClassFullName, culture, ReferencedAssemblyFiles, loadAssemblyIntoAppDomain);
}

public void Dispose ()
Expand Down

0 comments on commit 5f31951

Please sign in to comment.