Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9e1343c

Browse files
committed
Make the rest() function aware of @p.X and@p['X'] (breaking change)
1 parentccb6b01 commit9e1343c

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

‎src/Serilog.Expressions/Serilog.Expressions.csproj‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<Description>An embeddable mini-language for filtering, enriching, and formatting Serilog
55
events, ideal for use with JSON or XML configuration.</Description>
6-
<VersionPrefix>4.0.1</VersionPrefix>
6+
<VersionPrefix>5.0.0</VersionPrefix>
77
<Authors>Serilog Contributors</Authors>
88
<TargetFrameworks>netstandard2.1;netstandard2.0;net5.0;net6.0;net7.0</TargetFrameworks>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>

‎src/Serilog.Expressions/Templates/Compilation/UnreferencedProperties/ExpressionReferencedPropertiesFinder.cs‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
usingSerilog.Expressions;
1516
usingSerilog.Expressions.Ast;
17+
usingSerilog.Expressions.Compilation;
1618
usingSerilog.Expressions.Compilation.Transformations;
1719

1820
namespaceSerilog.Templates.Compilation.UnreferencedProperties;
@@ -47,7 +49,11 @@ protected override IEnumerable<string> Transform(LocalNameExpression nlx)
4749

4850
protectedoverrideIEnumerable<string>Transform(AccessorExpressionspx)
4951
{
50-
returnTransform(spx.Receiver);
52+
if(Pattern.IsAmbientProperty(spx.Receiver,BuiltInProperty.Properties,true))
53+
yieldreturnspx.MemberName;
54+
55+
foreach(varnestedinTransform(spx.Receiver))
56+
yieldreturnnested;
5157
}
5258

5359
protectedoverrideIEnumerable<string>Transform(LambdaExpressionlmx)
@@ -79,7 +85,18 @@ protected override IEnumerable<string> Transform(ObjectExpression ox)
7985

8086
protectedoverrideIEnumerable<string>Transform(IndexerExpressionix)
8187
{
82-
returnTransform(ix.Index).Concat(Transform(ix.Receiver));
88+
if(Pattern.IsAmbientProperty(ix.Receiver,BuiltInProperty.Properties,true)&&
89+
Pattern.IsStringConstant(ix.Index,outvarname))
90+
{
91+
yieldreturnname;
92+
}
93+
else
94+
{
95+
foreach(varnestedinTransform(ix.Index).Concat(Transform(ix.Receiver)))
96+
{
97+
yieldreturnnested;
98+
}
99+
}
83100
}
84101

85102
protectedoverrideIEnumerable<string>Transform(IndexOfMatchExpressionmx)

‎test/Serilog.Expressions.Tests/Templates/UnreferencedPropertiesFunctionTests.cs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,34 @@ public void UnreferencedPropertiesFunctionIsNamedRest()
1919
[Fact]
2020
publicvoidUnreferencedPropertiesExcludeThoseInMessageAndTemplate()
2121
{
22-
Assert.True(newTemplateParser().TryParse("{@m}{A + 1}{#if true}{B}{#end}",outvartemplate,out_));
22+
Assert.True(newTemplateParser().TryParse("{@m}{A + 1}{#if true}{B}{@p.C}{@p['D']}{#end}",outvartemplate,out_));
2323

24-
varfunction=newUnreferencedPropertiesFunction(template!);
24+
varfunction=newUnreferencedPropertiesFunction(template);
2525

2626
varevt=newLogEvent(
2727
DateTimeOffset.Now,
2828
LogEventLevel.Debug,
2929
null,
30-
new(new[]{newPropertyToken("C","{C}")}),
30+
new(new[]{newPropertyToken("E","{E}")}),
3131
new[]
3232
{
3333
newLogEventProperty("A",newScalarValue(null)),
3434
newLogEventProperty("B",newScalarValue(null)),
3535
newLogEventProperty("C",newScalarValue(null)),
3636
newLogEventProperty("D",newScalarValue(null)),
37+
newLogEventProperty("E",newScalarValue(null)),
38+
newLogEventProperty("F",newScalarValue(null)),
3739
});
3840

3941
vardeep=UnreferencedPropertiesFunction.Implementation(function,evt,newScalarValue(true));
4042

4143
varsv=Assert.IsType<StructureValue>(deep);
4244
varincluded=Assert.Single(sv.Properties);
43-
Assert.Equal("D",included!.Name);
45+
Assert.Equal("F",included.Name);
4446

4547
varshallow=UnreferencedPropertiesFunction.Implementation(function,evt);
4648
sv=Assert.IsType<StructureValue>(shallow);
47-
Assert.Contains(sv.Properties, p=>p.Name=="C");
48-
Assert.Contains(sv.Properties, p=>p.Name=="D");
49+
Assert.Contains(sv.Properties, p=>p.Name=="E");
50+
Assert.Contains(sv.Properties, p=>p.Name=="F");
4951
}
5052
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp