Class StiCSharpScriptParser

java.lang.Object
com.stimulsoft.base.parser.StiCSharpScriptParser

public class StiCSharpScriptParser extends Object
Parses and executes C# scripts.
  • Field Details

    • allowUsingDirective

      public static boolean allowUsingDirective
      A value indicating whether the 'using' directive is allowed in the script.
    • allowUsingSecurityMode

      public static boolean allowUsingSecurityMode
      A value indicating whether type creation should be restricted to whitelist. When true, only types from the whitelist can be instantiated. Default value is true for maximum security.
    • maxArraySize

      public static int maxArraySize
      The maximum allowed size for array creation. This limit prevents potential denial-of-service attacks through excessive memory allocation. Default value is 1,000,000 elements. Set to 0 to disable the limit (not recommended for security).
    • maxLoopIterations

      public static int maxLoopIterations
      The maximum allowed number of iterations for loops (for, while, do-while, foreach). This limit prevents potential denial-of-service attacks through infinite or very long loops. Default value is 1,000,000 iterations. Set to 0 to disable the limit (not recommended for security).
    • maxRecursionDepth

      public static int maxRecursionDepth
      The maximum allowed depth for recursion in method calls and expressions. This limit prevents potential stack overflow attacks through deep recursion. Default value is 100 levels. Set to 0 to disable the limit (not recommended for security).
  • Constructor Details

  • Method Details

    • getResult

      public final Object getResult()
    • execute

      public static Object execute(String script)
      Initializes a new instance of the StiParser class with the specified script text.
      Parameters:
      script -
      Returns:
    • execute

      public final Object execute()
      Starts the parsing and execution of the script.
      Returns:
      The result of the script execution.
    • execute

      public final Object execute(int timeoutMilliseconds)
    • setThisObject

      public final void setThisObject(Object thisObject)
    • setExternalObjectsProvider

      public final void setExternalObjectsProvider(StiCSharpScriptParser.IExternalObjectsProvider provider)
      Sets an external objects provider that can be used in the script.
    • registerFunction

      public final void registerFunction(String name, Function<Object[],Object> function)
      Registers a custom function that can be called from the script.
      Parameters:
      name - The function name.
      function - The function implementation.
    • registerNamespace

      public final void registerNamespace(String name)
      Registers a namespace that can be used from the script.
      Parameters:
      name - The namespace name.
    • getTokens

      public final ArrayList<StiToken> getTokens()
    • getTokenPositions

      public final ArrayList<StiCSharpScriptParser.TokenPosition> getTokenPositions()
    • GetType

      public final Class GetType(String name)
      Gets the type of a variable by its name.
    • setExternalTypesCache

      public final void setExternalTypesCache(HashMap nameToType)
    • setVariable

      public final void setVariable(String name, Object value)
      Sets a variable value that can be used in the script.
      Parameters:
      name - The variable name.
    • getVariable

      public final Object getVariable(String name)
      Gets a variable value from the script or external variable provider.
    • getVariableAsBool

      public final Boolean getVariableAsBool(String name)
      Gets a variable value as a string from the script or external variable provider.
    • getVariableAsInt

      public final Integer getVariableAsInt(String name)
      Gets a variable value as a string from the script or external variable provider.
    • getVariableAsLong

      public final Long getVariableAsLong(String name)
      Gets a variable value as a string from the script or external variable provider.
    • getVariableAsFloat

      public final Float getVariableAsFloat(String name)
      Gets a variable value as a string from the script or external variable provider.
    • getVariableAsDouble

      public final Double getVariableAsDouble(String name)
      Gets a variable value as a string from the script or external variable provider.
    • getVariableAsDecimal

      public final BigDecimal getVariableAsDecimal(String name)
      Gets a variable value as a string from the script or external variable provider.