Skip to content

Commit

Permalink
Merge branch 'master' into metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
sungam3r committed Mar 10, 2024
2 parents cc8b861 + 6de06e7 commit 5d94e1b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class PersonalData
public string? Name { get; set; }
}
```
<sup><a href='/src/Destructurama.Attributed.Tests/LogWithNameAttributeTests.cs#L29-L35' title='Snippet source file'>snippet source</a> | <a href='#snippet-logwithname' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Destructurama.Attributed.Tests/LogWithNameAttributeTests.cs#L63-L69' title='Snippet source file'>snippet source</a> | <a href='#snippet-logwithname' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## 2. Ignoring a property
Expand Down
35 changes: 35 additions & 0 deletions src/Destructurama.Attributed.Tests/LogWithNameAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,41 @@ public void AttributesAreConsultedWhenDestructuring(string name)
literalValue.ShouldBe(name);
}

// https://github.com/destructurama/attributed/issues/65
[Test]
public void Issue65()
{
var customized = new MessageBase
{
Context = new ContextClass(),
};
var evt = DelegatingSink.Execute(customized);
var sv = (StructureValue)evt.Properties["Customized"];
sv.Properties.Count.ShouldBe(1);
sv.Properties[0].Name.ShouldBe("messageContext");
var sv2 = sv.Properties[0].Value.ShouldBeOfType<StructureValue>();
sv2.Properties.Count.ShouldBe(2);
sv2.Properties[0].Name.ShouldBe("Foo");
sv2.Properties[1].Name.ShouldBe("Bar");
sv2.Properties[0].Value.LiteralValue().ShouldBe("MyFoo");
sv2.Properties[1].Value.LiteralValue().ShouldBe("MyBar");
}

public class MessageBase
{
[LogWithName("messageContext")]
public ContextClass? Context { get; set; }
}

public class ContextClass
{
public string Foo { get; set; } = "MyFoo";

public string Bar { get; set; } = "MyBar";

public override string ToString() => "ContextClass ToString Output";
}

#region LogWithName
public class PersonalData
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ public static LogEvent Execute(object obj, string messageTemplate = "Here is {@C

return evt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public LogWithNameAttribute(string newName)
/// <inheritdoc/>
public bool TryCreateLogEventProperty(string name, object? value, ILogEventPropertyValueFactory propertyValueFactory, [NotNullWhen(true)] out LogEventProperty? property)
{
property = new LogEventProperty(_newName, propertyValueFactory.CreatePropertyValue(value));
property = new LogEventProperty(_newName, propertyValueFactory.CreatePropertyValue(value, destructureObjects: true));
return true;
}
}

0 comments on commit 5d94e1b

Please sign in to comment.