1- // This work is licensed under the terms of the MIT license.
1+
2+ // This work is licensed under the terms of the MIT license.
23// For a copy, see <https://opensource.org/licenses/MIT>.
34
45namespace FuManchu . Renderer ;
@@ -16,7 +17,8 @@ namespace FuManchu.Renderer;
1617/// </summary>
1718public class RenderContext
1819{
19- private readonly Map _variables = new Map ( ) ;
20+ readonly Map _variables = new Map ( ) ;
21+ Map _parameters = new Map ( ) ;
2022
2123 /// <summary>
2224 /// Initializes a new instance of the <see cref="RenderContext"/> class.
@@ -103,6 +105,23 @@ public RenderContextScope BeginScope(object? model)
103105 return @default ;
104106 }
105107
108+ /// <summary>
109+ /// Gets the parameter with the given name.
110+ /// </summary>
111+ /// <param name="name">The parameter name.</param>
112+ /// <param name="default">[Optional] The default value for the parameter.</param>
113+ /// <returns>The parameter value.</returns>
114+ public object ? GetParameter ( string name , object ? @default )
115+ {
116+ object ? value ;
117+ if ( _variables . TryGetValue ( name , out value ) )
118+ {
119+ return value ;
120+ }
121+
122+ return @default ;
123+ }
124+
106125 /// <summary>
107126 /// Resolves the value represented by the given span.
108127 /// </summary>
@@ -274,6 +293,11 @@ public RenderContextScope BeginScope(object? model)
274293 expression = expression . Substring ( 5 ) ;
275294 }
276295
296+ if ( _parameters . TryGetValue ( expression , out var parameterValue ) )
297+ {
298+ return parameterValue ;
299+ }
300+
277301 var modelMetadata = ExpressionMetadataProvider . FromStringExpression ( expression , templateData , context . ModelMetadataProvider ) ;
278302 if ( modelMetadata == null || ! modelMetadata . Valid )
279303 {
@@ -295,4 +319,23 @@ public void SetVariable(string name, object value)
295319 {
296320 _variables [ name ] = value ;
297321 }
322+
323+ /// <summary>
324+ /// Sets the parameter with the given name.
325+ /// </summary>
326+ /// <param name="name">The name of the variable.</param>
327+ /// <param name="value">The variable value.</param>
328+ public void SetParameter ( string name , object value )
329+ {
330+ _parameters [ name ] = value ;
331+ }
332+
333+ /// <summary>
334+ /// Sets all parameters for the current context.
335+ /// </summary>
336+ /// <param name="parameters">The parameter map.</param>
337+ public void SetParameters ( Map parameters )
338+ {
339+ _parameters = parameters ?? new ( ) ;
340+ }
298341}
0 commit comments