XSalScript
Namespace: PPJ.Runtime.XSal
Assembly: PPJ.Web.XSal.50 (5.0.0.0)
Compiles and executes XSal-compatible or C# script text through the shared script engine.
- C#
- VB.NET
public class XSalScript
Public Class XSalScript
Example:
XSalScript script = new XSalScript("{ return 2 + 3; }");
string result = script.Run();
script.Dispose();
Constructors
XSalScript()
Creates a script with empty source and no compiled program.
XSalScript(source)
Creates a script and compiles nonempty source.
| Name | Type | Description |
|---|---|---|
| source | String | The script text; braces around the complete text enable C# syntax. |
Properties
Context
Object: Gets or sets the object used as the execution context for member lookup.
CSharpSyntax
Boolean: Gets or sets whether source is treated as C# syntax without XSal preprocessing. Changing this setting alone does not recompile the script.
DebugMode
Boolean: Gets or sets whether parser and interpreter exceptions are rethrown instead of captured in LastError.
Handle
IntPtr: Gets a lazily allocated GCHandle that keeps this script alive until Dispose releases it.
HasErrors
Boolean: Gets whether the most recently recorded error text is nonempty.
Interpreter
ScriptEngine: Gets or sets the shared script engine, lazily creating an engine when the stored value is null.
LastError
String: Gets the most recently captured parser or interpreter error, or null when the last compilation or execution cleared it.
Source
String: Gets or sets script source, preprocessing XSal syntax and compiling nonempty assignments.
A source beginning with { and ending with } turns on CSharpSyntax. Assigning null or empty text stores an empty string without clearing the previously compiled program or error.
Methods
AddLine(line)
Appends a source line with a line terminator and recompiles the program.
| Parameter | Type | Description |
|---|---|---|
| line | String | The line to append; null or empty text leaves the script unchanged. |
Returns: Boolean. True if compilation succeeds or the line is empty; false for a captured parser error.
Dispose()
Clears the execution context and releases the allocated handle, if any.
Finalize()
Clears the execution context and releases the allocated handle when the script is finalized.
FromHandle(handle)
Retrieves a script from its allocated GCHandle.
| Parameter | Type | Description |
|---|---|---|
| handle | IntPtr | A live handle obtained from XSalScript.Handle, or IntPtr.Zero. |
Returns: XSalScript. The referenced script, or null for IntPtr.Zero.
Run()
Executes the compiled program using Context.
Returns: String. The result converted to text, or an empty string for a null result, no compiled program, or a captured interpreter error.