Skip to content

Commit a1a2243

Browse files
committed
Some notes on how unsafe is implemented
1 parent dc89a23 commit a1a2243

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Serilog.Expressions/Templates/Encoding/EscapableEncodedCompiledFormattedExpression.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public EscapableEncodedCompiledFormattedExpression(Evaluatable expression, strin
1919
{
2020
_expression = expression;
2121
_encoder = encoder;
22+
23+
// `expression` can't be passed through, because it may include calls to the `unsafe()` function (nested in arbitrary subexpressions) that
24+
// need to be evaluated first. So, instead, we evaluate `expression` and unwrap the result of `unsafe`, placing the result in a local variable
25+
// that the formatting expression we construct here can read from.
2226
_inner = new CompiledFormattedExpression(GetSubstituteLocalValue, format, alignment, formatProvider, theme);
2327
}
2428

0 commit comments

Comments
 (0)