-
ScriptParser.AdditionalMethodHeaderCode to allow Code Injection at the generated Script Method Top
This property allows you to inject a string of code into each method generated by the ScriptParser after the Model has been passed and initialized. This can be useful for deconstructing the model so you can useTopic
instead ofModel.Topic
inside of the script, or for pre-initializing certain values and even functions to provide them for direct access in the script. -
Html Escaping via RawString()
Updated handling ofIRawString
behavior with aRawString()
class. You can use{{! expr }}
for explicitly not encoding content, or alternately use{{ Script.Raw(expr) }}
. If you create helper functions that are called from your script code, these can automatically enforce non-encoding by returning anIRawString
result which overrides any request for encoding (both default or explicit via{{: exp}}
)
-
Layout Page and Section Support for ScriptParser
The ScriptParser now supports Layout pages that can be referenced from a content page, to render an outer container page that typically is used for a site chrome header. The Layout and Content pages are merged into a single piece of code that is executed as a C# method. Content pages request a Layout page with{{% Script.Layout = "_layout.html" }}
and the content page renders into the Layout page via{{ Script.RenderContent() }}
. Content pages can use{{ Script.BeginSection("headers") }}
and the layout page can access those sections via{{ Script.RenderSection("headers" }}
. -
ScriptParser: New ScriptingDelimiters Property to replace passed Parameters
The script parser has a new property that contains all the scripting parameters, to simplify script delimiters and not forcing to pass it into each of the execute methods. This change removes all the optional delimiter parameters on the variousExecuteXXX()
methods. There's aScriptingDelimtiers.Default
property.
This is a breaking change -
ScriptParser: Allow escaping of
{{
and}}
with\{\{
and\}\}
The script parser now allows to escape{{
and}}
should they occur in your text. Since these are script delimiters they would otherwise not be usable. -
Html Encoding for script expressions {{: }} and raw {{! }}
Script expressions can now force Html Encoding with{{: expr }}
. Alternately to explicitly force raw output you can use{{! expr }}
. Defaults is now determined via a new ScriptDelimiters structure, including a newHtmlEncodeExpressionsByDefault
property which whentrue
encodes expressions. The default isfalse
(ie. no default Html encoding). -
Script Comments with {{@ content @}}
You can now comment content and code with{{@ any content @}}
. Content can span multiple lines and is processed before any other processing in the document occurs.
Note that comments require both a start and@
which is different than the other delimiters which only require a start character.
- CSharpScriptExecution.ExecuteMethodAsyncVoid for Async Void Methods
Due to the way tasks are handled in .NET it's not possible to cast a voidTask
to aTask<T>
result. For this reason separate methods are needed for the two versions ofExecuteMethodAsync()
andExecuteMethodAsync<TResult>()
asExecuteMethodAsyncVoid()
andExecuteMethodAsyncVoid<TResult>()
respectively. Use these methods if you explicitly don't want to return a value.
-
Add CSharpScriptExecution.AlternateAssemblyLoadContext which allows for Assembly Unloading
In .NET Core you can now assign an alternate AssemblyLoadContext to load assemblies into via theAlternateAssemblyLoadContext
, which allows for unloading of assemblies. PR #19 -
CSharpScriptExecution.DisableAssemblyCaching
By default this library caches generated assemblies based on the code that is passed in to execute. TheCSharpScriptExecution.DisableAssemblyCaching
property disables this caching in scenarios where you know code is never re-executed. PR #19
- Add .NET 8.0 Target Added explicit target for .NET 8.0.
-
Add .NET 7.0 Target
Added explicit target for .NET 7.0. -
Updated Roslyn Libraries with support for C# 11
Updated to latest Roslyn compiler libraries that support C# 11 syntax.
-
Breaking Change: ScriptParser Refactor to non-static Class
The original implementation of ScriptParser relied on severalstatic
methods to make it very easy to access and use. In this release ScriptParser is now a class that has be instantiated. -
ScriptParser includes ScriptEngine Property
The Script execution engine is now an auto-initialized property on the ScriptParser class. You can customize this instance or replace it with a custom instance. -
ScriptParser Simplification for ScriptEngine Access
Rather than requiring configuration directly on theScriptEngine
instance for dependencies and errors, the relevant properties have been forwarded to theScriptParser
class. You can now useAddAssembly()
/AddNameSpace()
and the variousError
,ErrorMessage
etc. properties directly on theScriptParser
instance which makes the code cleaner and exposes the relevant features only.
-
Add Stream Inputs for Class Compilation
The variousCompileClass()
methods now take stream inputs to allow directly reading from files or memory streams. -
Clean up Default References and Namespaces for .NET Core
Modified the default reference imports to create a minimal but somewhat functional baseline that allows running a variety of code running against common BCL/FCL functionality.
-
Switch to Roslyn CodeAnalysis APIs
Switched from CodeDom compilation to Roslyn CodeAnalysis compilation which improves compiler startup, compilation performance and provides more detailed compilation information on errors. -
Add Support for Async Execution
You can now use variousxxxAsync()
overloads to execute methods asTask
based operations that can beawait
ed and can useawait
inside of scripts. -
Add ScriptParser for C# Template Scripting
Added a very lightweight scripting engine that uses Handlebars style syntax for processing C# expressions and code blocks. Look at theScriptParser
class.
This version is a breaking change due to the changeover to the Roslyn APIs. While the APIs have stayed mostly the same, some of the dependent types have changed. Runtime requirements are also different with different libraries that are installed differently than the CodeDom dependencies. You may have to explicitly cleanup old application folders.
- Last CodeDom Version This version is the last version that works with CodeDom and that is fixed to .NET Framework. All later versions support .NET Framework and .NET Core.
-
Updated to latest Microsoft CodeDom libraries
Updated to the latest Microsoft CodeDom compilation libraries which streamline the compiler process for Roslyn compilation with latest language features. -
Remove support to pre .NET 4.72
In order to keep the runtime dependencies down switched the library target tonet472
which is .NET Standard compliant and so pulls in a much smaller set of dependencies. This is potentially a breaking change for older .NET applications, which will have to stick with the0.2.x
versions. -
Switch Projects to SDK Projects
Switched from classic .NET projects to the new simpler .NET SDK project format for the library and test projects.