ScriptParser Class

A very simple C# script parser that parses the provided script as a text string with embedded expressions and code blocks.

Literal text:

Parsed as plain text into the script output.

Expressions:

{{ DateTime.Now.ToString("d") }}

Code Blocks:

{{% for(int x; x<10; x++ } {{ x }}. Hello World {{% } }}

Uses the .ScriptEngine property for execution and provides error information there.

System.Object
   Westwind.Scripting.ScriptParser

Class Members

MemberDescription
Constructor
AddAssemblies Adds several assembly to the list of references for compilationusing a dll filenames.
public void AddAssemblies(String[] assemblies)
AddAssembly Adds an assembly to the list of references for compilationusing a dll filename
public void AddAssembly(string assemblyFile)
AddNamespace Add a namespace for compilation of the template
public void AddNamespace(string nameSpace)
AddNamespaces Add a list of namespaces for compilation of the template
public void AddNamespaces(String[] nameSpaces)
CreateScriptEngine Creates an instance of a script engine with default configuration settingsset and the abililty to quickly specify addition references and namespaces.You can pass this to…
public CSharpScriptExecution CreateScriptEngine(String[] references, String[] namespaces, Type[] referenceTypes)
EncodeStringLiteral Encodes a string to be represented as a C# style string literal.Example output:"Hello \"Rick\"!\r\nRock on"
public string EncodeStringLiteral(string plainString, bool addQuotes)
ExecuteScript Executes a script that supports {{ expression }} and {{% code block }} syntaxand returns a string result.You can optionally pass in a pre-configured `CSharpScriptExecution` instancewhich allows…
public string ExecuteScript(string script, object model, CSharpScriptExecution scriptEngine, string basePath)
ExecuteScriptAsync Executes a script that supports {{ expression }} and {{% code block }} syntaxand returns a string result. This version allows for `async` code inside ofthe template.You can optionally pass in a…
public Task ExecuteScriptAsync(string script, object model, CSharpScriptExecution scriptEngine, string basePath)
ExecuteScriptFile Executes a script that supports {{ expression }} and {{% code block }} syntaxand returns a string result.You can optionally pass in a pre-configured `CSharpScriptExecution` instancewhich allows…
public string ExecuteScriptFile(string scriptFile, object model, CSharpScriptExecution scriptEngine, string basePath)
ExecuteScriptFileAsync Executes a script that supports {{ expression }} and {{% code block }} syntaxand returns a string result.You can optionally pass in a pre-configured `CSharpScriptExecution` instancewhich allows…
public Task ExecuteScriptFileAsync(string scriptFile, object model, CSharpScriptExecution scriptEngine, string basePath)
FileScriptParsing This parses the script file and extracts layout and section informationand updates the `Script` property
public bool FileScriptParsing(ScriptFileContext context)
HtmlEncode Encodes a value using Html Encoding by first converting
public string HtmlEncode(object value)
ParseLayoutPage This is a helper function that ooks at the content page and retrieves the ScriptLayout directive,and then tries to the load the layout template.The code then looks for the content page and merges the…
public void ParseLayoutPage(ScriptFileContext context)
ParseScriptToCode Passes in a block of finalized 'script' code into a string usingcode that uses a text writer to output. You can feed theoutput from this method in `ExecuteCode()` or similar toparse the script into…
public string ParseScriptToCode(ScriptFileContext scriptContext)
ParseSections Parses out sections from the content page and assigns them into theScriptContext.Sections dictionary to be later expanded into the layoutpage.
public void ParseSections(ScriptFileContext scriptContext)
StripComments Strips {{@ commented block @}} from script
public string StripComments(string script)
AdditionalMethodHeaderCode Allows you to inject additional code into the generated methodthat executes the script.
Error Determines whether the was a compile time or runtime error
ErrorMessage Error Message if an error occurred
ErrorType Type of error that occurred during compilation or execution of the template
GeneratedClassCode Generated code that is compiled
GeneratedClassCodeWithLineNumbers Generated code with line numbers that is compiled. You can use thisto match error messages to code lines.
SaveGeneratedClassCode
ScriptEngine Script Engine used if none is passed in
ScriptingDelimiters Delimiters used for script parsing
Namespace: Westwind.Scripting

Assembly: Westwind.Scripting.dll