Zimmergren/LogAnalytics.Client

Support nullable properties

GunnarHakansson opened this issue · 1 comments

I think it would be a good idea to add support for the nullable versions of the approved property types. That is, not just int, Guid , DateTime, etc. But also int?, Guid? , DateTime? and so on.

If an entry has a value for a nullable property, it should be serialized normally. But, if the property value is null, that property should be omitted from the generated JSON.

Example:

public class ToLog
{
    public string Message { get; set; }
    public Guid? UserId { get; set; }
}
/*...*/
var with = new ToLog() {Message = "A", UserId = Guid.NewGuid()};
var without = new ToLog() { Message = "A", UserId = null };
await client.SendLogEntry(with, "TempTest");
await client.SendLogEntry(without, "TempTest");

This would produce:

[{"Message":"A","UserId":"7a87bd55-5389-4e13-a613-45d1e9b22997"}]

And:

[{"Message":"A"}]

Does this sound like an appropriate change? I can do it myself and send a Pull Request, or maybe you think it is easier to do it yourself?

Great - I'm open to enhancements like these.
Please submit a PR, and ensure the code is tested and produce the expected results. The more tests we can add to increase coverage, the better 👍 💪