C# Класс Scriban.TemplateContext

The template context contains the state of the page, the model.
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание
EnterFunction void
EnterLoop void
ExitFunction void
ExitLoop void
GetListAccessor IListAccessor
GetOrSetValue object
GetStoreForSet IEnumerable
GetValueInternal object
PopVariableScope void
PushVariableScope void
StepLoop bool

Открытые методы

Метод Описание
Evaluate ( ScriptNode scriptNode ) : object

Evaluates the specified script node.

Result is set to null when calling directly this method.

Evaluate ( ScriptNode scriptNode, bool aliasReturnedFunction ) : object

Evaluates the specified script node.

Result is set to null when calling directly this method.

GetDefaultBuiltinObject ( ) : ScriptObject

Gets a ScriptObject with all default builtins registered.

GetMemberAccessor ( object target ) : IMemberAccessor

Gets the member accessor for the specified object.

GetValue ( ScriptExpression target ) : object

Gets the value from the specified expression using the current ScriptObject bound to the model context.

PopGlobal ( ) : IScriptObject

Pops the previous model context.

PopOutput ( ) : string

Pops a previous output.

PopSourceFile ( ) : string

Pops the source file being executed.

PushGlobal ( IScriptObject scriptObject ) : void

Pushes a new model context accessible to the template.

PushOutput ( ) : void

Pushes a new output used for rendering the current template while keeping the previous output.

PushSourceFile ( string sourceFile ) : void

Pushes the source file path being executed. This should have enough information so that template loading/include can work correctly.

SetReadOnly ( ScriptVariable variable, bool isReadOnly = true ) : void

Sets the variable to read only.

This will not throw an exception if a previous variable was readonly.

SetValue ( ScriptExpression target, object value ) : void

Sets the target expression with the specified value.

SetValue ( ScriptVariable variable, object value, bool asReadOnly ) : void

Sets the variable with the specified value.

TemplateContext ( ) : System

Initializes a new instance of the TemplateContext class.

TemplateContext ( ScriptObject builtin ) : System

Initializes a new instance of the TemplateContext class.

Write ( SourceSpan span, object textAsObject ) : void

Writes an object value to the current Output.

Write ( string text ) : void

Writes the text to the current Output

Приватные методы

Метод Описание
EnterFunction ( ScriptNode caller ) : void
EnterLoop ( ScriptLoopStatementBase loop ) : void
ExitFunction ( ) : void
ExitLoop ( ) : void
GetListAccessor ( object target ) : IListAccessor
GetOrSetValue ( ScriptExpression targetExpression, object valueToSet, bool setter, int level ) : object
GetStoreForSet ( ScriptVariable variable ) : IEnumerable
GetValueInternal ( ScriptVariable variable ) : object
PopVariableScope ( ScriptVariableScope scope ) : void
PushVariableScope ( ScriptVariableScope scope ) : void
StepLoop ( ) : bool

Описание методов

Evaluate() публичный Метод

Evaluates the specified script node.
Result is set to null when calling directly this method.
public Evaluate ( ScriptNode scriptNode ) : object
scriptNode Scriban.Runtime.ScriptNode The script node.
Результат object

Evaluate() публичный Метод

Evaluates the specified script node.
Result is set to null when calling directly this method.
public Evaluate ( ScriptNode scriptNode, bool aliasReturnedFunction ) : object
scriptNode Scriban.Runtime.ScriptNode The script node.
aliasReturnedFunction bool if set to true and a function would be evaluated as part of this node, return the object function without evaluating it.
Результат object

GetDefaultBuiltinObject() публичный статический Метод

Gets a ScriptObject with all default builtins registered.
public static GetDefaultBuiltinObject ( ) : ScriptObject
Результат ScriptObject

GetMemberAccessor() публичный Метод

Gets the member accessor for the specified object.
public GetMemberAccessor ( object target ) : IMemberAccessor
target object The target object to get a member accessor.
Результат IMemberAccessor

GetValue() публичный Метод

Gets the value from the specified expression using the current ScriptObject bound to the model context.
public GetValue ( ScriptExpression target ) : object
target ScriptExpression The expression
Результат object

PopGlobal() публичный Метод

Pops the previous model context.
Unexpected PopGlobal() not matching a PushGlobal
public PopGlobal ( ) : IScriptObject
Результат IScriptObject

PopOutput() публичный Метод

Pops a previous output.
public PopOutput ( ) : string
Результат string

PopSourceFile() публичный Метод

Pops the source file being executed.
Cannot PopSourceFile more than PushSourceFile
public PopSourceFile ( ) : string
Результат string

PushGlobal() публичный Метод

Pushes a new model context accessible to the template.
public PushGlobal ( IScriptObject scriptObject ) : void
scriptObject IScriptObject The script object.
Результат void

PushOutput() публичный Метод

Pushes a new output used for rendering the current template while keeping the previous output.
public PushOutput ( ) : void
Результат void

PushSourceFile() публичный Метод

Pushes the source file path being executed. This should have enough information so that template loading/include can work correctly.
public PushSourceFile ( string sourceFile ) : void
sourceFile string The source file.
Результат void

SetReadOnly() публичный Метод

Sets the variable to read only.
This will not throw an exception if a previous variable was readonly.
If variable is null
public SetReadOnly ( ScriptVariable variable, bool isReadOnly = true ) : void
variable ScriptVariable The variable.
isReadOnly bool if set to true the variable will be set to readonly.
Результат void

SetValue() публичный Метод

Sets the target expression with the specified value.
If target is null
public SetValue ( ScriptExpression target, object value ) : void
target ScriptExpression The target expression.
value object The value.
Результат void

SetValue() публичный Метод

Sets the variable with the specified value.
If variable is null If an existing variable is already read-only
public SetValue ( ScriptVariable variable, object value, bool asReadOnly ) : void
variable ScriptVariable The variable.
value object The value.
asReadOnly bool if set to true the variable set will be read-only.
Результат void

TemplateContext() публичный Метод

Initializes a new instance of the TemplateContext class.
public TemplateContext ( ) : System
Результат System

TemplateContext() публичный Метод

Initializes a new instance of the TemplateContext class.
public TemplateContext ( ScriptObject builtin ) : System
builtin ScriptObject The builtin object used to expose builtin functions, default is .
Результат System

Write() публичный Метод

Writes an object value to the current Output.
public Write ( SourceSpan span, object textAsObject ) : void
span Scriban.Parsing.SourceSpan The span of the object to render.
textAsObject object The text as object.
Результат void

Write() публичный Метод

Writes the text to the current Output
public Write ( string text ) : void
text string The text.
Результат void