Code Macro Example
Using the code macro, you can create compiled executable .NET code directly from SXML. In the source code you need to define a .NET class deriving from Smartsite.Core.Module and provide an implementation for the Execute method in order to do something usefull. The se:code macro supports C# (= default), Visual Basic.NET, JScript 8.0 and Visual J# (the java language for .NET).
The se:code macro does not provide a security model, the source code has access to all resources on a machine. A more sandboxed model is being considered.
| Smartsite SXML |
|
|---|---|
{buffer.set(myvalue, 12345)}
<se:code error="{this.error.message()}">
using System;
using Smartsite.Core;
using Smartsite.Tools;
public class Class1: Module{
public override void Execute(){
Result.AppendLine("Hello C# world!");
Result.AppendLine("My value=" + Context.Buffers["myvalue"]);
}
}
</se:code>
<hr/>
<se:code language="VB" error="{this.error.message()}">
Public Class Class1
Inherits Smartsite.Core.Module
Public Overrides Sub Execute()
Result.AppendLine("Hello VB World!")
Result.AppendLine("My value=" & Context.Buffers("myvalue"))
End Sub
End Class
</se:code>
|
|
| Example Result |
|
|---|---|
Hello C# world! My value=12345 <hr /> Hello VB World! My value=12345 |
|