destructurama / attributed

Use attributes to control how complex types are logged to Serilog.
Apache License 2.0
269 stars 33 forks source link

Can't add attributes to properties of C#9 record classes (Attribute NotLogged is not valid on this dec type) #50

Closed goblinfactory closed 3 years ago

goblinfactory commented 3 years ago

Given I am using C# records I want to decorate PI properties with [NotLogged] attribute So that the properties are not logged

Example

   public record LoginRequest([Required][EmailAddress] string EmailAddress, [NotLogged][Required] string Password);

gives me a compile error, `Attribute NotLogged is not valid on this declaration type.

goblinfactory commented 3 years ago

Ah! Fixed... solution is to prefix the attribute with property. I never knew you could do this in C#... live and learn! maybe leave this issue open for a bit, so that I can create a PR some time to update documentation to show this? It's really useful to know.

fix like so ...

public record LoginRequest([Required][EmailAddress] string EmailAddress, [property:NotLogged][Required] string Password);
SimonCropp commented 3 years ago

there are many qwerks with records and properties. unfortunately it is not responsibility of this project to document those